jamboljack

Proses Kirim Invoice

Jan 7th, 2026
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.83 KB | None | 0 0
  1. private function process_invoice_simple($invoice_id)
  2.     {
  3.         try {
  4.             // 1. CEK INVOICE DI DATABASE
  5.             $invoice = $this->db->get_where('v_invoice', ['invoice_id' => $invoice_id])->row();
  6.             if (!$invoice) {
  7.                 return ['success' => false, 'message' => 'Invoice tidak ditemukan'];
  8.             }
  9.             // Jika sudah ada invoice_jurnal_id, skip
  10.             if (!empty($invoice->invoice_jurnal_id)) {
  11.                 return [
  12.                     'success' => true,
  13.                     'message' => 'Invoice sudah sync sebelumnya',
  14.                     'skip' => true
  15.                 ];
  16.             }
  17.            
  18.             // 2. CEK/SYNC CUSTOMER
  19.             $customer_result = $this->sync_customer_simple($invoice);
  20.             if (!$customer_result['success']) {
  21.                 return $customer_result;
  22.             }
  23.            
  24.             $customer_jurnal_id = $customer_result['jurnal_id'];
  25.            
  26.             if (!empty($invoice->invoice_jurnal_id)) {
  27.                 // Cek apakah masih ada di Mekari
  28.                 $exists = $this->check_invoice_exists_in_mekari($invoice->invoice_jurnal_id);
  29.                 if ($exists) {
  30.                     return ['success' => true, 'message' => 'Invoice sudah ada di Mekari', 'skip' => true];
  31.                 } else {
  32.                     // Jurnal ID tidak valid di Mekari, reset
  33.                     $this->db->where('invoice_id', $invoice->invoice_id)->update('sid_invoice', ['invoice_jurnal_id' => null]);
  34.                 }
  35.             }
  36.            
  37.             // 4. KIRIM INVOICE KE MEKARI dan SET PAID
  38.             return $this->send_invoice_simple($invoice, $customer_jurnal_id);
  39.            
  40.         } catch (Exception $e) {
  41.             return ['success' => false, 'message' => 'Error: ' . $e->getMessage()];
  42.         }
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment