Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.61 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Model_orders extends CI_Model {
  4.    
  5.     public function process()
  6.     {
  7.         //create new invoice
  8.         $invoice = array(
  9.             'date'      => date('Y-m-d H:i:s'),
  10.             'due_date'  => date('Y-m-d H:i:s', mktime( date('H'),date('i'),date('s'),date('m'),date('d') + 1,date('Y'))),
  11.             'status'    => 'unpaid'
  12.         );
  13.         $this->db->insert('invoices', $invoice);
  14.         $invoice_id = $this->db->insert_id();
  15.        
  16.         // put ordered items in orders table
  17.         foreach($this->cart->contents() as $item){
  18.             $data = array(
  19.                 'invoice_id'        => $invoice_id,
  20.                 'product_id'        => $item['id'],
  21.                 'product_name'      => $item['name'],
  22.                 'qty'               => $item['qty'],
  23.                 'price'             => $item['price']
  24.             );
  25.             $this->db->insert('orders', $data);
  26.         }
  27.        
  28.         return TRUE;
  29.     }
  30.    
  31.     public function all()
  32.     {
  33.         //Get all invoices from Invoices table
  34.         $hasil = $this->db->get('invoices');
  35.         if($hasil->num_rows() > 0){
  36.             return $hasil->result();
  37.         } else {
  38.             return false;
  39.         }
  40.     }
  41.  
  42.     public function get_invoice_by_id($invoice_id)
  43.     {
  44.         $hasil = $this->db->where('id',$invoice_id)->limit(1)->get('invoices');
  45.         if($hasil->num_rows() > 0){
  46.             return $hasil->row();
  47.         } else {
  48.             return false;
  49.         }
  50.     }
  51.  
  52.     public function get_orders_by_invoice($invoice_id)
  53.     {
  54.         $hasil = $this->db->where('invoice_id',$invoice_id)->get('orders');
  55.         if($hasil->num_rows() > 0){
  56.             return $hasil->result();
  57.         } else {
  58.             return false;
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement