Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private function process_invoice_simple($invoice_id)
- {
- try {
- // 1. CEK INVOICE DI DATABASE
- $invoice = $this->db->get_where('v_invoice', ['invoice_id' => $invoice_id])->row();
- if (!$invoice) {
- return ['success' => false, 'message' => 'Invoice tidak ditemukan'];
- }
- // Jika sudah ada invoice_jurnal_id, skip
- if (!empty($invoice->invoice_jurnal_id)) {
- return [
- 'success' => true,
- 'message' => 'Invoice sudah sync sebelumnya',
- 'skip' => true
- ];
- }
- // 2. CEK/SYNC CUSTOMER
- $customer_result = $this->sync_customer_simple($invoice);
- if (!$customer_result['success']) {
- return $customer_result;
- }
- $customer_jurnal_id = $customer_result['jurnal_id'];
- if (!empty($invoice->invoice_jurnal_id)) {
- // Cek apakah masih ada di Mekari
- $exists = $this->check_invoice_exists_in_mekari($invoice->invoice_jurnal_id);
- if ($exists) {
- return ['success' => true, 'message' => 'Invoice sudah ada di Mekari', 'skip' => true];
- } else {
- // Jurnal ID tidak valid di Mekari, reset
- $this->db->where('invoice_id', $invoice->invoice_id)->update('sid_invoice', ['invoice_jurnal_id' => null]);
- }
- }
- // 4. KIRIM INVOICE KE MEKARI dan SET PAID
- return $this->send_invoice_simple($invoice, $customer_jurnal_id);
- } catch (Exception $e) {
- return ['success' => false, 'message' => 'Error: ' . $e->getMessage()];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment