<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Jobcard
 *
 * @author Code sys PC 7
 */
class Jobcard extends CI_Model {

    public function __construct() {
        $this->load->database();
    }

    function saveJobCard($jobcard, $qout_id) {
        $this->db->delete('quotation_details', array('quotation_idquotation' => $qout_id));
        $this->db->delete('quotation', array('idquotation' => $qout_id));
        $this->db->insert("job_card", $jobcard);
        $insert_id = $this->db->insert_id();
        return $insert_id;
    }

    function saveJobCardDetails($jobcard_details) {
        $this->db->insert("job_card_details", $jobcard_details);
    }

    function jobCardCompleted($jobcard) {
        $this->db->where('idjob_card', $jobcard);
        $this->db->update("job_card", array('complete_status' => '1'));
        $this->db->select("job_card_qty");
        $this->db->select("customers_product_product_id");
        $jc_items = $this->db->get_where('job_card_details', array('job_card_idjob_card' => $jobcard));
        foreach ($jc_items->result() as $jc_itm) {
            $jcard_item = $jc_itm->customers_product_product_id;
            echo $jcard_item;
            $jc_stock_ar = array('job_card_idjob_card' => $jobcard, 'qty' => $jc_itm->job_card_qty, 'customers_product_product_id' => $jcard_item);
            $this->db->insert("job_card_stock", $jc_stock_ar);
        }
        redirect(base_url() . "index.php/Ui_controller/view_incomplete_jobcards");
    }

}
