FEAT: service and store bon commande, receiption, fournisseur
This commit is contained in:
parent
3bc4178a12
commit
0009eb8c86
@ -58,13 +58,13 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import FournisseurOverview from "@/components/molecules/fournisseur/FournisseurOverview.vue";
|
||||
import FournisseurInfoTab from "@/components/molecules/fournisseur/FournisseurInfoTab.vue";
|
||||
import FournisseurContactsTab from "@/components/molecules/fournisseur/FournisseurContactsTab.vue";
|
||||
import FournisseurAddressTab from "@/components/molecules/fournisseur/FournisseurAddressTab.vue";
|
||||
import FournisseurLocationsTab from "@/components/molecules/fournisseur/FournisseurLocationsTab.vue";
|
||||
import FournisseurNotesTab from "@/components/molecules/fournisseur/FournisseurNotesTab.vue";
|
||||
import FournisseurActivityTab from "@/components/molecules/fournisseur/FournisseurActivityTab.vue";
|
||||
import FournisseurOverview from "@/components/molecules/Fournisseur/FournisseurOverview.vue";
|
||||
import FournisseurInfoTab from "@/components/molecules/Fournisseur/FournisseurInfoTab.vue";
|
||||
import FournisseurContactsTab from "@/components/molecules/Fournisseur/FournisseurContactsTab.vue";
|
||||
import FournisseurAddressTab from "@/components/molecules/Fournisseur/FournisseurAddressTab.vue";
|
||||
import FournisseurLocationsTab from "@/components/molecules/Fournisseur/FournisseurLocationsTab.vue";
|
||||
import FournisseurNotesTab from "@/components/molecules/Fournisseur/FournisseurNotesTab.vue";
|
||||
import FournisseurActivityTab from "@/components/molecules/Fournisseur/FournisseurActivityTab.vue";
|
||||
import { defineProps, defineEmits } from "vue";
|
||||
|
||||
defineProps({
|
||||
|
||||
@ -26,8 +26,8 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import FournisseurProfileCard from "@/components/molecules/fournisseur/FournisseurProfileCard.vue";
|
||||
import FournisseurTabNavigation from "@/components/molecules/fournisseur/FournisseurTabNavigation.vue";
|
||||
import FournisseurProfileCard from "@/components/molecules/Fournisseur/FournisseurProfileCard.vue";
|
||||
import FournisseurTabNavigation from "@/components/molecules/Fournisseur/FournisseurTabNavigation.vue";
|
||||
import { defineProps, defineEmits } from "vue";
|
||||
defineProps({
|
||||
avatarUrl: {
|
||||
|
||||
151
thanasoft-front/src/services/avoir.ts
Normal file
151
thanasoft-front/src/services/avoir.ts
Normal file
@ -0,0 +1,151 @@
|
||||
import { request } from "./http";
|
||||
|
||||
export interface AvoirLine {
|
||||
id: number;
|
||||
avoir_id: number;
|
||||
product_id: number | null;
|
||||
invoice_line_id: number | null;
|
||||
description: string;
|
||||
quantity: number;
|
||||
unit_price: number;
|
||||
tva_rate: number;
|
||||
total_ht: number;
|
||||
total_tva: number;
|
||||
total_ttc: number;
|
||||
notes: string | null;
|
||||
product?: any;
|
||||
}
|
||||
|
||||
export interface Avoir {
|
||||
id: number;
|
||||
client_id: number;
|
||||
invoice_id: number | null;
|
||||
group_id: number | null;
|
||||
avoir_number: string;
|
||||
status: string;
|
||||
avoir_date: string;
|
||||
due_date: string | null;
|
||||
currency: string;
|
||||
total_ht: number;
|
||||
total_tva: number;
|
||||
total_ttc: number;
|
||||
reason_type: string | null;
|
||||
reason_description: string | null;
|
||||
e_invoice_status: string | null;
|
||||
refund_status: string | null;
|
||||
refund_date: string | null;
|
||||
refund_method: string | null;
|
||||
compensation_invoice_id: number | null;
|
||||
compensation_amount: number | null;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
client?: any;
|
||||
invoice?: any;
|
||||
group?: any;
|
||||
lines?: AvoirLine[];
|
||||
history?: any[];
|
||||
}
|
||||
|
||||
export interface AvoirListResponse {
|
||||
data: Avoir[];
|
||||
meta?: {
|
||||
current_page: number;
|
||||
last_page: number;
|
||||
per_page: number;
|
||||
total: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface AvoirResponse {
|
||||
data: Avoir;
|
||||
}
|
||||
|
||||
export interface CreateAvoirLinePayload {
|
||||
product_id?: number | null;
|
||||
invoice_line_id?: number | null;
|
||||
description: string;
|
||||
quantity: number;
|
||||
unit_price: number;
|
||||
tva_rate?: number;
|
||||
notes?: string | null;
|
||||
}
|
||||
|
||||
export interface CreateAvoirPayload {
|
||||
client_id: number;
|
||||
invoice_id?: number | null;
|
||||
group_id?: number | null;
|
||||
avoir_number?: string;
|
||||
status?: string;
|
||||
avoir_date?: string;
|
||||
due_date?: string | null;
|
||||
currency?: string;
|
||||
reason_type?: string | null;
|
||||
reason_description?: string | null;
|
||||
lines?: CreateAvoirLinePayload[];
|
||||
}
|
||||
|
||||
export interface UpdateAvoirPayload extends Partial<CreateAvoirPayload> {
|
||||
id: number;
|
||||
}
|
||||
|
||||
export const AvoirService = {
|
||||
async getAllAvoirs(params?: {
|
||||
page?: number;
|
||||
per_page?: number;
|
||||
search?: string;
|
||||
status?: string;
|
||||
client_id?: number;
|
||||
}): Promise<AvoirListResponse> {
|
||||
const response = await request<AvoirListResponse>({
|
||||
url: "/api/avoirs",
|
||||
method: "get",
|
||||
params,
|
||||
});
|
||||
return response;
|
||||
},
|
||||
|
||||
async getAvoir(id: number): Promise<AvoirResponse> {
|
||||
const response = await request<AvoirResponse>({
|
||||
url: `/api/avoirs/${id}`,
|
||||
method: "get",
|
||||
});
|
||||
return response;
|
||||
},
|
||||
|
||||
async createAvoir(payload: CreateAvoirPayload): Promise<AvoirResponse> {
|
||||
const response = await request<AvoirResponse>({
|
||||
url: "/api/avoirs",
|
||||
method: "post",
|
||||
data: payload,
|
||||
});
|
||||
return response;
|
||||
},
|
||||
|
||||
async updateAvoir(payload: UpdateAvoirPayload): Promise<AvoirResponse> {
|
||||
const { id, ...updateData } = payload;
|
||||
const response = await request<AvoirResponse>({
|
||||
url: `/api/avoirs/${id}`,
|
||||
method: "put",
|
||||
data: updateData,
|
||||
});
|
||||
return response;
|
||||
},
|
||||
|
||||
async deleteAvoir(id: number): Promise<{ success: boolean; message: string }> {
|
||||
const response = await request<{ success: boolean; message: string }>({
|
||||
url: `/api/avoirs/${id}`,
|
||||
method: "delete",
|
||||
});
|
||||
return response;
|
||||
},
|
||||
|
||||
async getByClient(clientId: number): Promise<AvoirListResponse> {
|
||||
const response = await request<AvoirListResponse>({
|
||||
url: `/api/clients/${clientId}/avoirs`,
|
||||
method: "get",
|
||||
});
|
||||
return response;
|
||||
},
|
||||
};
|
||||
|
||||
export default AvoirService;
|
||||
124
thanasoft-front/src/services/goodsReceipt.ts
Normal file
124
thanasoft-front/src/services/goodsReceipt.ts
Normal file
@ -0,0 +1,124 @@
|
||||
import { request } from "./http";
|
||||
|
||||
export interface GoodsReceiptLine {
|
||||
id: number;
|
||||
goods_receipt_id: number;
|
||||
product_id: number;
|
||||
purchase_order_line_id: number | null;
|
||||
quantity_received: number;
|
||||
unit_price: number | null;
|
||||
notes: string | null;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
product?: any;
|
||||
}
|
||||
|
||||
export interface GoodsReceipt {
|
||||
id: number;
|
||||
purchase_order_id: number;
|
||||
receipt_number: string;
|
||||
receipt_date: string;
|
||||
status: 'brouillon' | 'valide' | 'annule';
|
||||
notes: string | null;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
purchase_order?: any;
|
||||
lines?: GoodsReceiptLine[];
|
||||
}
|
||||
|
||||
export interface GoodsReceiptListResponse {
|
||||
data: GoodsReceipt[];
|
||||
meta?: {
|
||||
current_page: number;
|
||||
last_page: number;
|
||||
per_page: number;
|
||||
total: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface GoodsReceiptResponse {
|
||||
data: GoodsReceipt;
|
||||
}
|
||||
|
||||
export interface CreateGoodsReceiptLinePayload {
|
||||
product_id: number;
|
||||
purchase_order_line_id?: number | null;
|
||||
quantity_received: number;
|
||||
unit_price?: number | null;
|
||||
notes?: string | null;
|
||||
}
|
||||
|
||||
export interface CreateGoodsReceiptPayload {
|
||||
purchase_order_id: number;
|
||||
receipt_number?: string;
|
||||
receipt_date?: string;
|
||||
status?: string;
|
||||
notes?: string | null;
|
||||
lines?: CreateGoodsReceiptLinePayload[];
|
||||
}
|
||||
|
||||
export interface UpdateGoodsReceiptPayload extends Partial<CreateGoodsReceiptPayload> {
|
||||
id: number;
|
||||
}
|
||||
|
||||
export const GoodsReceiptService = {
|
||||
async getAllGoodsReceipts(params?: {
|
||||
page?: number;
|
||||
per_page?: number;
|
||||
search?: string;
|
||||
status?: string;
|
||||
purchase_order_id?: number;
|
||||
}): Promise<GoodsReceiptListResponse> {
|
||||
const response = await request<GoodsReceiptListResponse>({
|
||||
url: "/api/goods-receipts",
|
||||
method: "get",
|
||||
params,
|
||||
});
|
||||
return response;
|
||||
},
|
||||
|
||||
async getGoodsReceipt(id: number): Promise<GoodsReceiptResponse> {
|
||||
const response = await request<GoodsReceiptResponse>({
|
||||
url: `/api/goods-receipts/${id}`,
|
||||
method: "get",
|
||||
});
|
||||
return response;
|
||||
},
|
||||
|
||||
async createGoodsReceipt(payload: CreateGoodsReceiptPayload): Promise<GoodsReceiptResponse> {
|
||||
const response = await request<GoodsReceiptResponse>({
|
||||
url: "/api/goods-receipts",
|
||||
method: "post",
|
||||
data: payload,
|
||||
});
|
||||
return response;
|
||||
},
|
||||
|
||||
async updateGoodsReceipt(payload: UpdateGoodsReceiptPayload): Promise<GoodsReceiptResponse> {
|
||||
const { id, ...updateData } = payload;
|
||||
const response = await request<GoodsReceiptResponse>({
|
||||
url: `/api/goods-receipts/${id}`,
|
||||
method: "put",
|
||||
data: updateData,
|
||||
});
|
||||
return response;
|
||||
},
|
||||
|
||||
async deleteGoodsReceipt(id: number): Promise<{ success: boolean; message: string }> {
|
||||
const response = await request<{ success: boolean; message: string }>({
|
||||
url: `/api/goods-receipts/${id}`,
|
||||
method: "delete",
|
||||
});
|
||||
return response;
|
||||
},
|
||||
|
||||
async getByPurchaseOrder(purchaseOrderId: number): Promise<GoodsReceiptListResponse> {
|
||||
const response = await request<GoodsReceiptListResponse>({
|
||||
url: `/api/purchase-orders/${purchaseOrderId}/goods-receipts`,
|
||||
method: "get",
|
||||
});
|
||||
return response;
|
||||
},
|
||||
};
|
||||
|
||||
export default GoodsReceiptService;
|
||||
136
thanasoft-front/src/services/purchaseOrder.ts
Normal file
136
thanasoft-front/src/services/purchaseOrder.ts
Normal file
@ -0,0 +1,136 @@
|
||||
import { request } from "./http";
|
||||
|
||||
export interface PurchaseOrderLine {
|
||||
id: number;
|
||||
purchase_order_id: number;
|
||||
product_id: number | null;
|
||||
description: string;
|
||||
quantity: number;
|
||||
unit_price: number;
|
||||
tva_rate: number;
|
||||
discount_pct: number;
|
||||
total_ht: number;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
product?: any;
|
||||
}
|
||||
|
||||
export interface PurchaseOrder {
|
||||
id: number;
|
||||
fournisseur_id: number;
|
||||
po_number: string;
|
||||
status: 'brouillon' | 'confirmee' | 'livree' | 'facturee' | 'annulee';
|
||||
order_date: string;
|
||||
expected_date: string | null;
|
||||
currency: string;
|
||||
total_ht: number;
|
||||
total_tva: number;
|
||||
total_ttc: number;
|
||||
notes: string | null;
|
||||
delivery_address: string | null;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
fournisseur?: any;
|
||||
lines?: PurchaseOrderLine[];
|
||||
}
|
||||
|
||||
export interface PurchaseOrderListResponse {
|
||||
data: PurchaseOrder[];
|
||||
meta?: {
|
||||
current_page: number;
|
||||
last_page: number;
|
||||
per_page: number;
|
||||
total: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface PurchaseOrderResponse {
|
||||
data: PurchaseOrder;
|
||||
}
|
||||
|
||||
export interface CreatePurchaseOrderLinePayload {
|
||||
product_id?: number | null;
|
||||
description: string;
|
||||
quantity: number;
|
||||
unit_price: number;
|
||||
tva_rate?: number;
|
||||
discount_pct?: number;
|
||||
}
|
||||
|
||||
export interface CreatePurchaseOrderPayload {
|
||||
fournisseur_id: number;
|
||||
po_number?: string;
|
||||
status?: string;
|
||||
order_date?: string;
|
||||
expected_date?: string | null;
|
||||
currency?: string;
|
||||
notes?: string | null;
|
||||
delivery_address?: string | null;
|
||||
lines?: CreatePurchaseOrderLinePayload[];
|
||||
}
|
||||
|
||||
export interface UpdatePurchaseOrderPayload extends Partial<CreatePurchaseOrderPayload> {
|
||||
id: number;
|
||||
}
|
||||
|
||||
export const PurchaseOrderService = {
|
||||
async getAllPurchaseOrders(params?: {
|
||||
page?: number;
|
||||
per_page?: number;
|
||||
search?: string;
|
||||
status?: string;
|
||||
fournisseur_id?: number;
|
||||
}): Promise<PurchaseOrderListResponse> {
|
||||
const response = await request<PurchaseOrderListResponse>({
|
||||
url: "/api/purchase-orders",
|
||||
method: "get",
|
||||
params,
|
||||
});
|
||||
return response;
|
||||
},
|
||||
|
||||
async getPurchaseOrder(id: number): Promise<PurchaseOrderResponse> {
|
||||
const response = await request<PurchaseOrderResponse>({
|
||||
url: `/api/purchase-orders/${id}`,
|
||||
method: "get",
|
||||
});
|
||||
return response;
|
||||
},
|
||||
|
||||
async createPurchaseOrder(payload: CreatePurchaseOrderPayload): Promise<PurchaseOrderResponse> {
|
||||
const response = await request<PurchaseOrderResponse>({
|
||||
url: "/api/purchase-orders",
|
||||
method: "post",
|
||||
data: payload,
|
||||
});
|
||||
return response;
|
||||
},
|
||||
|
||||
async updatePurchaseOrder(payload: UpdatePurchaseOrderPayload): Promise<PurchaseOrderResponse> {
|
||||
const { id, ...updateData } = payload;
|
||||
const response = await request<PurchaseOrderResponse>({
|
||||
url: `/api/purchase-orders/${id}`,
|
||||
method: "put",
|
||||
data: updateData,
|
||||
});
|
||||
return response;
|
||||
},
|
||||
|
||||
async deletePurchaseOrder(id: number): Promise<{ success: boolean; message: string }> {
|
||||
const response = await request<{ success: boolean; message: string }>({
|
||||
url: `/api/purchase-orders/${id}`,
|
||||
method: "delete",
|
||||
});
|
||||
return response;
|
||||
},
|
||||
|
||||
async getByFournisseur(fournisseurId: number): Promise<PurchaseOrderListResponse> {
|
||||
const response = await request<PurchaseOrderListResponse>({
|
||||
url: `/api/fournisseurs/${fournisseurId}/purchase-orders`,
|
||||
method: "get",
|
||||
});
|
||||
return response;
|
||||
},
|
||||
};
|
||||
|
||||
export default PurchaseOrderService;
|
||||
137
thanasoft-front/src/services/supplierInvoice.ts
Normal file
137
thanasoft-front/src/services/supplierInvoice.ts
Normal file
@ -0,0 +1,137 @@
|
||||
import { request } from "./http";
|
||||
|
||||
export interface SupplierInvoiceLine {
|
||||
id: number;
|
||||
supplier_invoice_id: number;
|
||||
product_id: number | null;
|
||||
purchase_order_line_id: number | null;
|
||||
description: string;
|
||||
quantity: number;
|
||||
unit_price: number;
|
||||
tva_rate: number;
|
||||
total_ht: number;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
product?: any;
|
||||
}
|
||||
|
||||
export interface SupplierInvoice {
|
||||
id: number;
|
||||
fournisseur_id: number;
|
||||
purchase_order_id: number | null;
|
||||
invoice_number: string;
|
||||
invoice_date: string;
|
||||
due_date: string | null;
|
||||
status: 'brouillon' | 'en_attente' | 'payee' | 'annulee';
|
||||
currency: string;
|
||||
total_ht: number;
|
||||
total_tva: number;
|
||||
total_ttc: number;
|
||||
notes: string | null;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
fournisseur?: any;
|
||||
purchase_order?: any;
|
||||
lines?: SupplierInvoiceLine[];
|
||||
}
|
||||
|
||||
export interface SupplierInvoiceListResponse {
|
||||
data: SupplierInvoice[];
|
||||
meta?: {
|
||||
current_page: number;
|
||||
last_page: number;
|
||||
per_page: number;
|
||||
total: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface SupplierInvoiceResponse {
|
||||
data: SupplierInvoice;
|
||||
}
|
||||
|
||||
export interface CreateSupplierInvoiceLinePayload {
|
||||
product_id?: number | null;
|
||||
purchase_order_line_id?: number | null;
|
||||
description: string;
|
||||
quantity: number;
|
||||
unit_price: number;
|
||||
tva_rate?: number;
|
||||
}
|
||||
|
||||
export interface CreateSupplierInvoicePayload {
|
||||
fournisseur_id: number;
|
||||
purchase_order_id?: number | null;
|
||||
invoice_number?: string;
|
||||
invoice_date?: string;
|
||||
due_date?: string | null;
|
||||
status?: string;
|
||||
currency?: string;
|
||||
notes?: string | null;
|
||||
lines?: CreateSupplierInvoiceLinePayload[];
|
||||
}
|
||||
|
||||
export interface UpdateSupplierInvoicePayload extends Partial<CreateSupplierInvoicePayload> {
|
||||
id: number;
|
||||
}
|
||||
|
||||
export const SupplierInvoiceService = {
|
||||
async getAllSupplierInvoices(params?: {
|
||||
page?: number;
|
||||
per_page?: number;
|
||||
search?: string;
|
||||
status?: string;
|
||||
fournisseur_id?: number;
|
||||
}): Promise<SupplierInvoiceListResponse> {
|
||||
const response = await request<SupplierInvoiceListResponse>({
|
||||
url: "/api/supplier-invoices",
|
||||
method: "get",
|
||||
params,
|
||||
});
|
||||
return response;
|
||||
},
|
||||
|
||||
async getSupplierInvoice(id: number): Promise<SupplierInvoiceResponse> {
|
||||
const response = await request<SupplierInvoiceResponse>({
|
||||
url: `/api/supplier-invoices/${id}`,
|
||||
method: "get",
|
||||
});
|
||||
return response;
|
||||
},
|
||||
|
||||
async createSupplierInvoice(payload: CreateSupplierInvoicePayload): Promise<SupplierInvoiceResponse> {
|
||||
const response = await request<SupplierInvoiceResponse>({
|
||||
url: "/api/supplier-invoices",
|
||||
method: "post",
|
||||
data: payload,
|
||||
});
|
||||
return response;
|
||||
},
|
||||
|
||||
async updateSupplierInvoice(payload: UpdateSupplierInvoicePayload): Promise<SupplierInvoiceResponse> {
|
||||
const { id, ...updateData } = payload;
|
||||
const response = await request<SupplierInvoiceResponse>({
|
||||
url: `/api/supplier-invoices/${id}`,
|
||||
method: "put",
|
||||
data: updateData,
|
||||
});
|
||||
return response;
|
||||
},
|
||||
|
||||
async deleteSupplierInvoice(id: number): Promise<{ success: boolean; message: string }> {
|
||||
const response = await request<{ success: boolean; message: string }>({
|
||||
url: `/api/supplier-invoices/${id}`,
|
||||
method: "delete",
|
||||
});
|
||||
return response;
|
||||
},
|
||||
|
||||
async getByFournisseur(fournisseurId: number): Promise<SupplierInvoiceListResponse> {
|
||||
const response = await request<SupplierInvoiceListResponse>({
|
||||
url: `/api/fournisseurs/${fournisseurId}/supplier-invoices`,
|
||||
method: "get",
|
||||
});
|
||||
return response;
|
||||
},
|
||||
};
|
||||
|
||||
export default SupplierInvoiceService;
|
||||
256
thanasoft-front/src/stores/avoirStore.ts
Normal file
256
thanasoft-front/src/stores/avoirStore.ts
Normal file
@ -0,0 +1,256 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { ref, computed } from "vue";
|
||||
import AvoirService from "@/services/avoir";
|
||||
|
||||
import type {
|
||||
Avoir,
|
||||
CreateAvoirPayload,
|
||||
UpdateAvoirPayload,
|
||||
} from "@/services/avoir";
|
||||
|
||||
export const useAvoirStore = defineStore("avoir", () => {
|
||||
const avoirs = ref<Avoir[]>([]);
|
||||
const currentAvoir = ref<Avoir | null>(null);
|
||||
const loading = ref(false);
|
||||
const error = ref<string | null>(null);
|
||||
|
||||
const pagination = ref({
|
||||
current_page: 1,
|
||||
last_page: 1,
|
||||
per_page: 10,
|
||||
total: 0,
|
||||
});
|
||||
|
||||
const allAvoirs = computed(() => avoirs.value);
|
||||
const isLoading = computed(() => loading.value);
|
||||
const hasError = computed(() => error.value !== null);
|
||||
const getError = computed(() => error.value);
|
||||
const getAvoirById = computed(() => (id: number) =>
|
||||
avoirs.value.find((avoir) => avoir.id === id)
|
||||
);
|
||||
const getPagination = computed(() => pagination.value);
|
||||
|
||||
const setLoading = (isLoading: boolean) => {
|
||||
loading.value = isLoading;
|
||||
};
|
||||
|
||||
const setError = (err: string | null) => {
|
||||
error.value = err;
|
||||
};
|
||||
|
||||
const clearError = () => {
|
||||
error.value = null;
|
||||
};
|
||||
|
||||
const setAvoirs = (newAvoirs: Avoir[]) => {
|
||||
avoirs.value = newAvoirs;
|
||||
};
|
||||
|
||||
const setCurrentAvoir = (avoir: Avoir | null) => {
|
||||
currentAvoir.value = avoir;
|
||||
};
|
||||
|
||||
const setPagination = (meta: any) => {
|
||||
if (meta) {
|
||||
pagination.value = {
|
||||
current_page: meta.current_page || 1,
|
||||
last_page: meta.last_page || 1,
|
||||
per_page: meta.per_page || 10,
|
||||
total: meta.total || 0,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const fetchAvoirs = async (params?: {
|
||||
page?: number;
|
||||
per_page?: number;
|
||||
search?: string;
|
||||
status?: string;
|
||||
client_id?: number;
|
||||
}) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await AvoirService.getAllAvoirs(params);
|
||||
setAvoirs(response.data);
|
||||
if (response.meta) {
|
||||
setPagination(response.meta);
|
||||
}
|
||||
return response;
|
||||
} catch (err: any) {
|
||||
const errorMessage =
|
||||
err.response?.data?.message ||
|
||||
err.message ||
|
||||
"Erreur lors de la récupération des avoirs";
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchAvoir = async (id: number) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await AvoirService.getAvoir(id);
|
||||
setCurrentAvoir(response.data);
|
||||
return response.data;
|
||||
} catch (err: any) {
|
||||
const errorMessage =
|
||||
err.response?.data?.message ||
|
||||
err.message ||
|
||||
"Erreur lors de la récupération de l'avoir";
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const createAvoir = async (payload: CreateAvoirPayload) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await AvoirService.createAvoir(payload);
|
||||
avoirs.value.push(response.data);
|
||||
setCurrentAvoir(response.data);
|
||||
return response.data;
|
||||
} catch (err: any) {
|
||||
const errorMessage =
|
||||
err.response?.data?.message ||
|
||||
err.message ||
|
||||
"Erreur lors de la création de l'avoir";
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const updateAvoir = async (payload: UpdateAvoirPayload) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await AvoirService.updateAvoir(payload);
|
||||
const updatedAvoir = response.data;
|
||||
|
||||
const index = avoirs.value.findIndex(
|
||||
(avoir) => avoir.id === updatedAvoir.id
|
||||
);
|
||||
if (index !== -1) {
|
||||
avoirs.value[index] = updatedAvoir;
|
||||
}
|
||||
|
||||
if (
|
||||
currentAvoir.value &&
|
||||
currentAvoir.value.id === updatedAvoir.id
|
||||
) {
|
||||
setCurrentAvoir(updatedAvoir);
|
||||
}
|
||||
|
||||
return updatedAvoir;
|
||||
} catch (err: any) {
|
||||
const errorMessage =
|
||||
err.response?.data?.message ||
|
||||
err.message ||
|
||||
"Erreur lors de la mise à jour de l'avoir";
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const deleteAvoir = async (id: number) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await AvoirService.deleteAvoir(id);
|
||||
|
||||
avoirs.value = avoirs.value.filter(
|
||||
(avoir) => avoir.id !== id
|
||||
);
|
||||
|
||||
if (currentAvoir.value && currentAvoir.value.id === id) {
|
||||
setCurrentAvoir(null);
|
||||
}
|
||||
|
||||
return response;
|
||||
} catch (err: any) {
|
||||
const errorMessage =
|
||||
err.response?.data?.message ||
|
||||
err.message ||
|
||||
"Erreur lors de la suppression de l'avoir";
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchByClient = async (clientId: number) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await AvoirService.getByClient(clientId);
|
||||
setAvoirs(response.data);
|
||||
return response.data;
|
||||
} catch (err: any) {
|
||||
const errorMessage =
|
||||
err.response?.data?.message ||
|
||||
err.message ||
|
||||
"Erreur lors de la récupération des avoirs du client";
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const clearCurrentAvoir = () => {
|
||||
setCurrentAvoir(null);
|
||||
};
|
||||
|
||||
const clearStore = () => {
|
||||
avoirs.value = [];
|
||||
currentAvoir.value = null;
|
||||
error.value = null;
|
||||
pagination.value = {
|
||||
current_page: 1,
|
||||
last_page: 1,
|
||||
per_page: 10,
|
||||
total: 0,
|
||||
};
|
||||
};
|
||||
|
||||
return {
|
||||
avoirs,
|
||||
currentAvoir,
|
||||
loading,
|
||||
error,
|
||||
|
||||
allAvoirs,
|
||||
isLoading,
|
||||
hasError,
|
||||
getError,
|
||||
getAvoirById,
|
||||
getPagination,
|
||||
|
||||
fetchAvoirs,
|
||||
fetchAvoir,
|
||||
createAvoir,
|
||||
updateAvoir,
|
||||
deleteAvoir,
|
||||
fetchByClient,
|
||||
clearCurrentAvoir,
|
||||
clearStore,
|
||||
clearError,
|
||||
};
|
||||
});
|
||||
268
thanasoft-front/src/stores/goodsReceiptStore.ts
Normal file
268
thanasoft-front/src/stores/goodsReceiptStore.ts
Normal file
@ -0,0 +1,268 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { ref, computed } from "vue";
|
||||
import GoodsReceiptService from "@/services/goodsReceipt";
|
||||
|
||||
import type {
|
||||
GoodsReceipt,
|
||||
CreateGoodsReceiptPayload,
|
||||
UpdateGoodsReceiptPayload,
|
||||
} from "@/services/goodsReceipt";
|
||||
|
||||
export const useGoodsReceiptStore = defineStore("goodsReceipt", () => {
|
||||
const goodsReceipts = ref<GoodsReceipt[]>([]);
|
||||
const currentGoodsReceipt = ref<GoodsReceipt | null>(null);
|
||||
const loading = ref(false);
|
||||
const error = ref<string | null>(null);
|
||||
|
||||
const pagination = ref({
|
||||
current_page: 1,
|
||||
last_page: 1,
|
||||
per_page: 10,
|
||||
total: 0,
|
||||
});
|
||||
|
||||
const allGoodsReceipts = computed(() => goodsReceipts.value);
|
||||
const draftReceipts = computed(() =>
|
||||
goodsReceipts.value.filter((receipt) => receipt.status === "brouillon")
|
||||
);
|
||||
const validatedReceipts = computed(() =>
|
||||
goodsReceipts.value.filter((receipt) => receipt.status === "valide")
|
||||
);
|
||||
const cancelledReceipts = computed(() =>
|
||||
goodsReceipts.value.filter((receipt) => receipt.status === "annule")
|
||||
);
|
||||
const isLoading = computed(() => loading.value);
|
||||
const hasError = computed(() => error.value !== null);
|
||||
const getError = computed(() => error.value);
|
||||
const getGoodsReceiptById = computed(() => (id: number) =>
|
||||
goodsReceipts.value.find((receipt) => receipt.id === id)
|
||||
);
|
||||
const getPagination = computed(() => pagination.value);
|
||||
|
||||
const setLoading = (isLoading: boolean) => {
|
||||
loading.value = isLoading;
|
||||
};
|
||||
|
||||
const setError = (err: string | null) => {
|
||||
error.value = err;
|
||||
};
|
||||
|
||||
const clearError = () => {
|
||||
error.value = null;
|
||||
};
|
||||
|
||||
const setGoodsReceipts = (newGoodsReceipts: GoodsReceipt[]) => {
|
||||
goodsReceipts.value = newGoodsReceipts;
|
||||
};
|
||||
|
||||
const setCurrentGoodsReceipt = (receipt: GoodsReceipt | null) => {
|
||||
currentGoodsReceipt.value = receipt;
|
||||
};
|
||||
|
||||
const setPagination = (meta: any) => {
|
||||
if (meta) {
|
||||
pagination.value = {
|
||||
current_page: meta.current_page || 1,
|
||||
last_page: meta.last_page || 1,
|
||||
per_page: meta.per_page || 10,
|
||||
total: meta.total || 0,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const fetchGoodsReceipts = async (params?: {
|
||||
page?: number;
|
||||
per_page?: number;
|
||||
search?: string;
|
||||
status?: string;
|
||||
purchase_order_id?: number;
|
||||
}) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await GoodsReceiptService.getAllGoodsReceipts(params);
|
||||
setGoodsReceipts(response.data);
|
||||
if (response.meta) {
|
||||
setPagination(response.meta);
|
||||
}
|
||||
return response;
|
||||
} catch (err: any) {
|
||||
const errorMessage =
|
||||
err.response?.data?.message ||
|
||||
err.message ||
|
||||
"Erreur lors de la récupération des réceptions";
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchGoodsReceipt = async (id: number) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await GoodsReceiptService.getGoodsReceipt(id);
|
||||
setCurrentGoodsReceipt(response.data);
|
||||
return response.data;
|
||||
} catch (err: any) {
|
||||
const errorMessage =
|
||||
err.response?.data?.message ||
|
||||
err.message ||
|
||||
"Erreur lors de la récupération de la réception";
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const createGoodsReceipt = async (payload: CreateGoodsReceiptPayload) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await GoodsReceiptService.createGoodsReceipt(payload);
|
||||
goodsReceipts.value.push(response.data);
|
||||
setCurrentGoodsReceipt(response.data);
|
||||
return response.data;
|
||||
} catch (err: any) {
|
||||
const errorMessage =
|
||||
err.response?.data?.message ||
|
||||
err.message ||
|
||||
"Erreur lors de la création de la réception";
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const updateGoodsReceipt = async (payload: UpdateGoodsReceiptPayload) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await GoodsReceiptService.updateGoodsReceipt(payload);
|
||||
const updatedReceipt = response.data;
|
||||
|
||||
const index = goodsReceipts.value.findIndex(
|
||||
(receipt) => receipt.id === updatedReceipt.id
|
||||
);
|
||||
if (index !== -1) {
|
||||
goodsReceipts.value[index] = updatedReceipt;
|
||||
}
|
||||
|
||||
if (
|
||||
currentGoodsReceipt.value &&
|
||||
currentGoodsReceipt.value.id === updatedReceipt.id
|
||||
) {
|
||||
setCurrentGoodsReceipt(updatedReceipt);
|
||||
}
|
||||
|
||||
return updatedReceipt;
|
||||
} catch (err: any) {
|
||||
const errorMessage =
|
||||
err.response?.data?.message ||
|
||||
err.message ||
|
||||
"Erreur lors de la mise à jour de la réception";
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const deleteGoodsReceipt = async (id: number) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await GoodsReceiptService.deleteGoodsReceipt(id);
|
||||
|
||||
goodsReceipts.value = goodsReceipts.value.filter(
|
||||
(receipt) => receipt.id !== id
|
||||
);
|
||||
|
||||
if (currentGoodsReceipt.value && currentGoodsReceipt.value.id === id) {
|
||||
setCurrentGoodsReceipt(null);
|
||||
}
|
||||
|
||||
return response;
|
||||
} catch (err: any) {
|
||||
const errorMessage =
|
||||
err.response?.data?.message ||
|
||||
err.message ||
|
||||
"Erreur lors de la suppression de la réception";
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchByPurchaseOrder = async (purchaseOrderId: number) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await GoodsReceiptService.getByPurchaseOrder(purchaseOrderId);
|
||||
setGoodsReceipts(response.data);
|
||||
return response.data;
|
||||
} catch (err: any) {
|
||||
const errorMessage =
|
||||
err.response?.data?.message ||
|
||||
err.message ||
|
||||
"Erreur lors de la récupération des réceptions de la commande";
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const clearCurrentGoodsReceipt = () => {
|
||||
setCurrentGoodsReceipt(null);
|
||||
};
|
||||
|
||||
const clearStore = () => {
|
||||
goodsReceipts.value = [];
|
||||
currentGoodsReceipt.value = null;
|
||||
error.value = null;
|
||||
pagination.value = {
|
||||
current_page: 1,
|
||||
last_page: 1,
|
||||
per_page: 10,
|
||||
total: 0,
|
||||
};
|
||||
};
|
||||
|
||||
return {
|
||||
goodsReceipts,
|
||||
currentGoodsReceipt,
|
||||
loading,
|
||||
error,
|
||||
|
||||
allGoodsReceipts,
|
||||
draftReceipts,
|
||||
validatedReceipts,
|
||||
cancelledReceipts,
|
||||
isLoading,
|
||||
hasError,
|
||||
getError,
|
||||
getGoodsReceiptById,
|
||||
getPagination,
|
||||
|
||||
fetchGoodsReceipts,
|
||||
fetchGoodsReceipt,
|
||||
createGoodsReceipt,
|
||||
updateGoodsReceipt,
|
||||
deleteGoodsReceipt,
|
||||
fetchByPurchaseOrder,
|
||||
clearCurrentGoodsReceipt,
|
||||
clearStore,
|
||||
clearError,
|
||||
};
|
||||
});
|
||||
272
thanasoft-front/src/stores/purchaseOrderStore.ts
Normal file
272
thanasoft-front/src/stores/purchaseOrderStore.ts
Normal file
@ -0,0 +1,272 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { ref, computed } from "vue";
|
||||
import PurchaseOrderService from "@/services/purchaseOrder";
|
||||
|
||||
import type {
|
||||
PurchaseOrder,
|
||||
CreatePurchaseOrderPayload,
|
||||
UpdatePurchaseOrderPayload,
|
||||
} from "@/services/purchaseOrder";
|
||||
|
||||
export const usePurchaseOrderStore = defineStore("purchaseOrder", () => {
|
||||
const purchaseOrders = ref<PurchaseOrder[]>([]);
|
||||
const currentPurchaseOrder = ref<PurchaseOrder | null>(null);
|
||||
const loading = ref(false);
|
||||
const error = ref<string | null>(null);
|
||||
|
||||
const pagination = ref({
|
||||
current_page: 1,
|
||||
last_page: 1,
|
||||
per_page: 10,
|
||||
total: 0,
|
||||
});
|
||||
|
||||
const allPurchaseOrders = computed(() => purchaseOrders.value);
|
||||
const draftOrders = computed(() =>
|
||||
purchaseOrders.value.filter((order) => order.status === "brouillon")
|
||||
);
|
||||
const confirmedOrders = computed(() =>
|
||||
purchaseOrders.value.filter((order) => order.status === "confirmee")
|
||||
);
|
||||
const deliveredOrders = computed(() =>
|
||||
purchaseOrders.value.filter((order) => order.status === "livree")
|
||||
);
|
||||
const invoicedOrders = computed(() =>
|
||||
purchaseOrders.value.filter((order) => order.status === "facturee")
|
||||
);
|
||||
const isLoading = computed(() => loading.value);
|
||||
const hasError = computed(() => error.value !== null);
|
||||
const getError = computed(() => error.value);
|
||||
const getPurchaseOrderById = computed(() => (id: number) =>
|
||||
purchaseOrders.value.find((order) => order.id === id)
|
||||
);
|
||||
const getPagination = computed(() => pagination.value);
|
||||
|
||||
const setLoading = (isLoading: boolean) => {
|
||||
loading.value = isLoading;
|
||||
};
|
||||
|
||||
const setError = (err: string | null) => {
|
||||
error.value = err;
|
||||
};
|
||||
|
||||
const clearError = () => {
|
||||
error.value = null;
|
||||
};
|
||||
|
||||
const setPurchaseOrders = (newPurchaseOrders: PurchaseOrder[]) => {
|
||||
purchaseOrders.value = newPurchaseOrders;
|
||||
};
|
||||
|
||||
const setCurrentPurchaseOrder = (order: PurchaseOrder | null) => {
|
||||
currentPurchaseOrder.value = order;
|
||||
};
|
||||
|
||||
const setPagination = (meta: any) => {
|
||||
if (meta) {
|
||||
pagination.value = {
|
||||
current_page: meta.current_page || 1,
|
||||
last_page: meta.last_page || 1,
|
||||
per_page: meta.per_page || 10,
|
||||
total: meta.total || 0,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const fetchPurchaseOrders = async (params?: {
|
||||
page?: number;
|
||||
per_page?: number;
|
||||
search?: string;
|
||||
status?: string;
|
||||
fournisseur_id?: number;
|
||||
}) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await PurchaseOrderService.getAllPurchaseOrders(params);
|
||||
setPurchaseOrders(response.data);
|
||||
if (response.meta) {
|
||||
setPagination(response.meta);
|
||||
}
|
||||
return response;
|
||||
} catch (err: any) {
|
||||
const errorMessage =
|
||||
err.response?.data?.message ||
|
||||
err.message ||
|
||||
"Erreur lors de la récupération des commandes";
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchPurchaseOrder = async (id: number) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await PurchaseOrderService.getPurchaseOrder(id);
|
||||
setCurrentPurchaseOrder(response.data);
|
||||
return response.data;
|
||||
} catch (err: any) {
|
||||
const errorMessage =
|
||||
err.response?.data?.message ||
|
||||
err.message ||
|
||||
"Erreur lors de la récupération de la commande";
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const createPurchaseOrder = async (payload: CreatePurchaseOrderPayload) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await PurchaseOrderService.createPurchaseOrder(payload);
|
||||
purchaseOrders.value.push(response.data);
|
||||
setCurrentPurchaseOrder(response.data);
|
||||
return response.data;
|
||||
} catch (err: any) {
|
||||
const errorMessage =
|
||||
err.response?.data?.message ||
|
||||
err.message ||
|
||||
"Erreur lors de la création de la commande";
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const updatePurchaseOrder = async (payload: UpdatePurchaseOrderPayload) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await PurchaseOrderService.updatePurchaseOrder(payload);
|
||||
const updatedOrder = response.data;
|
||||
|
||||
const index = purchaseOrders.value.findIndex(
|
||||
(order) => order.id === updatedOrder.id
|
||||
);
|
||||
if (index !== -1) {
|
||||
purchaseOrders.value[index] = updatedOrder;
|
||||
}
|
||||
|
||||
if (
|
||||
currentPurchaseOrder.value &&
|
||||
currentPurchaseOrder.value.id === updatedOrder.id
|
||||
) {
|
||||
setCurrentPurchaseOrder(updatedOrder);
|
||||
}
|
||||
|
||||
return updatedOrder;
|
||||
} catch (err: any) {
|
||||
const errorMessage =
|
||||
err.response?.data?.message ||
|
||||
err.message ||
|
||||
"Erreur lors de la mise à jour de la commande";
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const deletePurchaseOrder = async (id: number) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await PurchaseOrderService.deletePurchaseOrder(id);
|
||||
|
||||
purchaseOrders.value = purchaseOrders.value.filter(
|
||||
(order) => order.id !== id
|
||||
);
|
||||
|
||||
if (currentPurchaseOrder.value && currentPurchaseOrder.value.id === id) {
|
||||
setCurrentPurchaseOrder(null);
|
||||
}
|
||||
|
||||
return response;
|
||||
} catch (err: any) {
|
||||
const errorMessage =
|
||||
err.response?.data?.message ||
|
||||
err.message ||
|
||||
"Erreur lors de la suppression de la commande";
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchByFournisseur = async (fournisseurId: number) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await PurchaseOrderService.getByFournisseur(fournisseurId);
|
||||
setPurchaseOrders(response.data);
|
||||
return response.data;
|
||||
} catch (err: any) {
|
||||
const errorMessage =
|
||||
err.response?.data?.message ||
|
||||
err.message ||
|
||||
"Erreur lors de la récupération des commandes du fournisseur";
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const clearCurrentPurchaseOrder = () => {
|
||||
setCurrentPurchaseOrder(null);
|
||||
};
|
||||
|
||||
const clearStore = () => {
|
||||
purchaseOrders.value = [];
|
||||
currentPurchaseOrder.value = null;
|
||||
error.value = null;
|
||||
pagination.value = {
|
||||
current_page: 1,
|
||||
last_page: 1,
|
||||
per_page: 10,
|
||||
total: 0,
|
||||
};
|
||||
};
|
||||
|
||||
return {
|
||||
purchaseOrders,
|
||||
currentPurchaseOrder,
|
||||
loading,
|
||||
error,
|
||||
|
||||
allPurchaseOrders,
|
||||
draftOrders,
|
||||
confirmedOrders,
|
||||
deliveredOrders,
|
||||
invoicedOrders,
|
||||
isLoading,
|
||||
hasError,
|
||||
getError,
|
||||
getPurchaseOrderById,
|
||||
getPagination,
|
||||
|
||||
fetchPurchaseOrders,
|
||||
fetchPurchaseOrder,
|
||||
createPurchaseOrder,
|
||||
updatePurchaseOrder,
|
||||
deletePurchaseOrder,
|
||||
fetchByFournisseur,
|
||||
clearCurrentPurchaseOrder,
|
||||
clearStore,
|
||||
clearError,
|
||||
};
|
||||
});
|
||||
272
thanasoft-front/src/stores/supplierInvoiceStore.ts
Normal file
272
thanasoft-front/src/stores/supplierInvoiceStore.ts
Normal file
@ -0,0 +1,272 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { ref, computed } from "vue";
|
||||
import SupplierInvoiceService from "@/services/supplierInvoice";
|
||||
|
||||
import type {
|
||||
SupplierInvoice,
|
||||
CreateSupplierInvoicePayload,
|
||||
UpdateSupplierInvoicePayload,
|
||||
} from "@/services/supplierInvoice";
|
||||
|
||||
export const useSupplierInvoiceStore = defineStore("supplierInvoice", () => {
|
||||
const supplierInvoices = ref<SupplierInvoice[]>([]);
|
||||
const currentSupplierInvoice = ref<SupplierInvoice | null>(null);
|
||||
const loading = ref(false);
|
||||
const error = ref<string | null>(null);
|
||||
|
||||
const pagination = ref({
|
||||
current_page: 1,
|
||||
last_page: 1,
|
||||
per_page: 10,
|
||||
total: 0,
|
||||
});
|
||||
|
||||
const allSupplierInvoices = computed(() => supplierInvoices.value);
|
||||
const draftInvoices = computed(() =>
|
||||
supplierInvoices.value.filter((invoice) => invoice.status === "brouillon")
|
||||
);
|
||||
const pendingInvoices = computed(() =>
|
||||
supplierInvoices.value.filter((invoice) => invoice.status === "en_attente")
|
||||
);
|
||||
const paidInvoices = computed(() =>
|
||||
supplierInvoices.value.filter((invoice) => invoice.status === "payee")
|
||||
);
|
||||
const cancelledInvoices = computed(() =>
|
||||
supplierInvoices.value.filter((invoice) => invoice.status === "annulee")
|
||||
);
|
||||
const isLoading = computed(() => loading.value);
|
||||
const hasError = computed(() => error.value !== null);
|
||||
const getError = computed(() => error.value);
|
||||
const getSupplierInvoiceById = computed(() => (id: number) =>
|
||||
supplierInvoices.value.find((invoice) => invoice.id === id)
|
||||
);
|
||||
const getPagination = computed(() => pagination.value);
|
||||
|
||||
const setLoading = (isLoading: boolean) => {
|
||||
loading.value = isLoading;
|
||||
};
|
||||
|
||||
const setError = (err: string | null) => {
|
||||
error.value = err;
|
||||
};
|
||||
|
||||
const clearError = () => {
|
||||
error.value = null;
|
||||
};
|
||||
|
||||
const setSupplierInvoices = (newSupplierInvoices: SupplierInvoice[]) => {
|
||||
supplierInvoices.value = newSupplierInvoices;
|
||||
};
|
||||
|
||||
const setCurrentSupplierInvoice = (invoice: SupplierInvoice | null) => {
|
||||
currentSupplierInvoice.value = invoice;
|
||||
};
|
||||
|
||||
const setPagination = (meta: any) => {
|
||||
if (meta) {
|
||||
pagination.value = {
|
||||
current_page: meta.current_page || 1,
|
||||
last_page: meta.last_page || 1,
|
||||
per_page: meta.per_page || 10,
|
||||
total: meta.total || 0,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const fetchSupplierInvoices = async (params?: {
|
||||
page?: number;
|
||||
per_page?: number;
|
||||
search?: string;
|
||||
status?: string;
|
||||
fournisseur_id?: number;
|
||||
}) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await SupplierInvoiceService.getAllSupplierInvoices(params);
|
||||
setSupplierInvoices(response.data);
|
||||
if (response.meta) {
|
||||
setPagination(response.meta);
|
||||
}
|
||||
return response;
|
||||
} catch (err: any) {
|
||||
const errorMessage =
|
||||
err.response?.data?.message ||
|
||||
err.message ||
|
||||
"Erreur lors de la récupération des factures fournisseurs";
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchSupplierInvoice = async (id: number) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await SupplierInvoiceService.getSupplierInvoice(id);
|
||||
setCurrentSupplierInvoice(response.data);
|
||||
return response.data;
|
||||
} catch (err: any) {
|
||||
const errorMessage =
|
||||
err.response?.data?.message ||
|
||||
err.message ||
|
||||
"Erreur lors de la récupération de la facture fournisseur";
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const createSupplierInvoice = async (payload: CreateSupplierInvoicePayload) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await SupplierInvoiceService.createSupplierInvoice(payload);
|
||||
supplierInvoices.value.push(response.data);
|
||||
setCurrentSupplierInvoice(response.data);
|
||||
return response.data;
|
||||
} catch (err: any) {
|
||||
const errorMessage =
|
||||
err.response?.data?.message ||
|
||||
err.message ||
|
||||
"Erreur lors de la création de la facture fournisseur";
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const updateSupplierInvoice = async (payload: UpdateSupplierInvoicePayload) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await SupplierInvoiceService.updateSupplierInvoice(payload);
|
||||
const updatedInvoice = response.data;
|
||||
|
||||
const index = supplierInvoices.value.findIndex(
|
||||
(invoice) => invoice.id === updatedInvoice.id
|
||||
);
|
||||
if (index !== -1) {
|
||||
supplierInvoices.value[index] = updatedInvoice;
|
||||
}
|
||||
|
||||
if (
|
||||
currentSupplierInvoice.value &&
|
||||
currentSupplierInvoice.value.id === updatedInvoice.id
|
||||
) {
|
||||
setCurrentSupplierInvoice(updatedInvoice);
|
||||
}
|
||||
|
||||
return updatedInvoice;
|
||||
} catch (err: any) {
|
||||
const errorMessage =
|
||||
err.response?.data?.message ||
|
||||
err.message ||
|
||||
"Erreur lors de la mise à jour de la facture fournisseur";
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const deleteSupplierInvoice = async (id: number) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await SupplierInvoiceService.deleteSupplierInvoice(id);
|
||||
|
||||
supplierInvoices.value = supplierInvoices.value.filter(
|
||||
(invoice) => invoice.id !== id
|
||||
);
|
||||
|
||||
if (currentSupplierInvoice.value && currentSupplierInvoice.value.id === id) {
|
||||
setCurrentSupplierInvoice(null);
|
||||
}
|
||||
|
||||
return response;
|
||||
} catch (err: any) {
|
||||
const errorMessage =
|
||||
err.response?.data?.message ||
|
||||
err.message ||
|
||||
"Erreur lors de la suppression de la facture fournisseur";
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchByFournisseur = async (fournisseurId: number) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await SupplierInvoiceService.getByFournisseur(fournisseurId);
|
||||
setSupplierInvoices(response.data);
|
||||
return response.data;
|
||||
} catch (err: any) {
|
||||
const errorMessage =
|
||||
err.response?.data?.message ||
|
||||
err.message ||
|
||||
"Erreur lors de la récupération des factures du fournisseur";
|
||||
setError(errorMessage);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const clearCurrentSupplierInvoice = () => {
|
||||
setCurrentSupplierInvoice(null);
|
||||
};
|
||||
|
||||
const clearStore = () => {
|
||||
supplierInvoices.value = [];
|
||||
currentSupplierInvoice.value = null;
|
||||
error.value = null;
|
||||
pagination.value = {
|
||||
current_page: 1,
|
||||
last_page: 1,
|
||||
per_page: 10,
|
||||
total: 0,
|
||||
};
|
||||
};
|
||||
|
||||
return {
|
||||
supplierInvoices,
|
||||
currentSupplierInvoice,
|
||||
loading,
|
||||
error,
|
||||
|
||||
allSupplierInvoices,
|
||||
draftInvoices,
|
||||
pendingInvoices,
|
||||
paidInvoices,
|
||||
cancelledInvoices,
|
||||
isLoading,
|
||||
hasError,
|
||||
getError,
|
||||
getSupplierInvoiceById,
|
||||
getPagination,
|
||||
|
||||
fetchSupplierInvoices,
|
||||
fetchSupplierInvoice,
|
||||
createSupplierInvoice,
|
||||
updateSupplierInvoice,
|
||||
deleteSupplierInvoice,
|
||||
fetchByFournisseur,
|
||||
clearCurrentSupplierInvoice,
|
||||
clearStore,
|
||||
clearError,
|
||||
};
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user