Exemple #1
0
 public function delete($id)
 {
     $this->db->trans_begin();
     try {
         $update = $this->user->delete($id);
         if (!$update) {
             throw new ErrorException('Delete user gagal.');
         }
         $this->db->trans_commit();
         return json_view('success');
     } catch (ErrorException $e) {
         $this->db->trans_rollback();
         return json_view('failed');
     }
 }
Exemple #2
0
 public function pay($id)
 {
     $this->db->trans_begin();
     try {
         $this->commition->isPaid = '1';
         $update = $this->commition->update($id, $this->commition);
         if (!$update) {
             throw new ErrorException('');
         }
         $this->db->trans_commit();
         return json_view('success');
     } catch (ErrorException $e) {
         $this->db->trans_rollback();
         return json_view($e->getMessage());
     }
 }
Exemple #3
0
 public function update($id)
 {
     $this->db->trans_begin();
     try {
         $this->news->title = $this->input->post('title');
         $this->news->content = $this->input->post('content');
         $update = $this->news->update($id, $this->news);
         if (!$update) {
             throw new ErrorException('Simpan berita gagal.');
         }
         $this->db->trans_commit();
         return json_view('success');
     } catch (Exception $e) {
         $this->db->trans_rollback();
         return json_view('failed');
     }
 }
Exemple #4
0
 public function confirm($payment_id, $invoice_id)
 {
     $this->db->trans_begin();
     try {
         // Update payment status konfirmasi pembayaran di set 1 jika nasabah sudah melakukan pembayaran
         $this->payment->isConfirmed = '1';
         $update = $this->payment->update($payment_id, $this->payment);
         if (!$update) {
             throw new ErrorException('konfirmasi pembayaran gagal.');
         }
         // Updata status invoice juga bahwa invoice sudah dibayar
         $this->invoice->isPaid = '1';
         $this->invoice->update($invoice_id, $this->invoice);
         // Update order dengan mengambil order id dari invoice yang sudah dibayar
         $this->db->where('id', $invoice_id);
         $this->db->select('order_id, total');
         $this->db->from('invoices');
         $result = $this->db->get()->result();
         $order_id = $result[0]->order_id;
         $total = $result[0]->total;
         $this->order->status = 'active';
         $this->order->due_date = add_date(date('Y-m-d'), 0, 12, 0);
         $this->order->update($order_id, $this->order);
         // Create income generate otomatis jika sudah melakukan pembayaran pada order ini
         $profit_per_month = 2 / 100 * $total;
         for ($i = 1; $i < 13; $i++) {
             $this->income->order_id = $order_id;
             $this->income->total = $profit_per_month;
             $this->income->due_date = add_date(date('Y-m-d'), 0, $i, 0);
             $this->income->status = $i % 3 == 0 ? 'active' : 'inactive';
             $this->income->insert($this->income);
         }
         $this->db->trans_commit();
         return json_view('success');
     } catch (ErrorException $e) {
         $this->db->trans_rollback();
         return json_view('failed');
     }
 }
Exemple #5
0
 public function save_invoice($id)
 {
     $this->db->trans_begin();
     try {
         $this->invoice->order_id = $id;
         $this->invoice->no = $this->input->post('no');
         $this->invoice->due_date = add_date(date('Y-m-d'), 1, 0, 0);
         $this->invoice->total = $this->input->post('total');
         $save = $this->invoice->insert($this->invoice);
         if (!$save) {
             throw new ErrorException('Menyimpan invoice gagal.');
         }
         //Update orders after invoice created
         $this->order->isInvoiceCreated = '1';
         $this->order->update($id, $this->order);
         $this->db->trans_commit();
         return json_view('success');
     } catch (ErrorException $e) {
         $this->db->trans_rollback();
         return json_view($e->getMessage());
     }
 }