Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- require_once APPPATH . '/../vendor/autoload.php';
- class Sales extends CI_Controller {
- function __construct() {
- parent::__construct();
- $this->load->model('sales_model');
- $this->load->model('quotation_model');
- $this->load->model('customer_model');
- $this->load->model('category_model');
- $this->load->model('brand_model');
- $this->load->model('bank_model');
- $this->load->model('purchase_model');
- $this->load->model('company_setting_model');
- $this->load->model('kurs_model');
- $this->load->model('signature_model');
- $this->load->model('general_model');
- $this->load->model('log_model');
- }
- public function randomKey($length) {
- $key = '';
- $pool = array_merge(range(0, 9), range('a', 'z'), range('A', 'Z'));
- for ($i = 0; $i < $length; $i++) {
- $key .= $pool[mt_rand(0, count($pool) - 1)];
- }
- return $key;
- }
- public function alert($msg) {
- echo "<script type='text/javascript'>system.log('$msg');</script>";
- }
- public function index() {
- // get all sales to display list
- $filter = null;
- if(isset($_GET['filter'])) {
- if ($_GET['filter'] != null) {
- $filter = $_GET['filter'];
- }
- }
- $data['quotation'] = $this->quotation_model->getQuotation();
- $data['data'] = $this->sales_model->getSales($filter);
- $this->load->view('sales/list', $data);
- }
- /*
- call add view to add sales record
- */
- public function add() {
- $kursdata = $this->company_setting_model->getCurrency();
- $data['country'] = $this->db->get('countries')->result();
- $data['brands'] = $this->brand_model->getBrand();
- $data['warehouse'] = $this->sales_model->getWarehouse();
- $data['quotation'] = $this->quotation_model->getQuotation();
- $data['warehouse_products'] = $this->sales_model->getWarehouseProducts();
- $data['tax'] = $this->sales_model->getTax();
- $data['biller'] = $this->sales_model->getBiller();
- $data['customer'] = $this->sales_model->getCustomer();
- $data['quatation'] = $this->sales_model->getQuatation();
- $data['product'] = $this->sales_model->getProducts2();
- $data['service'] = $this->sales_model->getService();
- $data['discount'] = $this->sales_model->getDiscount();
- $data['kursdata'] = $kursdata;
- $data['reference_no'] = $this->sales_model->createReferenceNo();
- $data['so_number'] = $this->general_model->generateAutoNumber('sales_order');
- $this->load->view('sales/add', $data);
- }
- /*
- this function is used to get discount data when discount is change
- */
- public function getDiscountAjax($id) {
- $data = $this->sales_model->getDiscountAjax($id);
- echo json_encode($data);
- }
- /* get all product warehouse wise */
- public function getProducts($warehouse_id) {
- $data = $this->sales_model->getProducts($warehouse_id);
- echo json_encode($data);
- }
- public function getPartNumber($brand_id) {
- $data = $this->sales_model->getPartNumber($brand_id);
- echo json_encode($data);
- }
- public function getCodeProduct($code) {
- $data = $this->sales_model->getCodeProduct($code);
- echo json_encode($data);
- }
- /* get single product */
- public function getProduct($product_id,$sales_id) {
- $datas = $this->sales_model->getProducts21($product_id);
- // print_r(var_dump($this->db->last_query()));
- for ($i=0; $i < count($datas) ; $i++) {
- if ($datas[$i]->product_grouping != NULL) {
- $arlist = json_encode(unserialize($datas[$i]->list));
- $arlist = json_decode($arlist);
- $max = array();
- for ($ilist = 0; $ilist < count($arlist); $ilist++) {
- $qtyp = $this->db->select('quantity')->from('products')->where('product_id', $arlist[$ilist]->pl)->get()->result()[0]->quantity;
- $count = ($qtyp / intval($arlist[$ilist]->ql));
- array_push($max, $count);
- }
- $min = min($max);
- $datas[$i]->quantity = intval($min);
- }
- }
- $data['items'] = $this->sales_model->getProducts99($sales_id);
- $data['discount'] = $this->sales_model->getDiscount();
- $data['bonus'] = $this->sales_model->getBonus($product_id);
- $data['bonus1'] = $this->sales_model->getBonus12();
- $data['tax'] = $this->sales_model->getTax();
- echo json_encode($data);
- }
- public function getService($service_id) {
- $data = $this->sales_model->getServicetable($service_id);
- $data['discount'] = $this->sales_model->getDiscount();
- $data['tax'] = $this->sales_model->getTax();
- echo json_encode($data);
- }
- /*
- this function is used to search product name / code in auto complite
- */
- public function getAutoCodeName($code, $search_option, $warehouse) {
- //$code = strtolower($code);
- $p_code = $this->input->post('p_code');
- $p_search_option = $this->input->post('p_search_option');
- $data = $this->sales_model->getProductCodeName($p_code, $p_search_option, $warehouse);
- if ($search_option == "Code") {
- $list = "<ul class='auto-product'>";
- foreach ($data as $val) {
- $list .= "<li value=" . $val->code . ">" . $val->code . "</li>";
- }
- $list .= "</ul>";
- } else {
- $list = "<ul class='auto-product'>";
- foreach ($data as $val) {
- $list .= "<li value=" . $val->product_id . ">" . $val->name . "</li>";
- }
- $list .= "</ul>";
- }
- echo $list;
- //echo json_encode($data);
- //print_r($data);
- }
- /*
- this fucntion is used to add sales record in database
- */
- public function addSales() {
- date_default_timezone_set("Asia/Bangkok");
- $submit = $this->input->post('submit');
- if ($submit == "Publish") {
- $status = 0;
- } else {
- $status = 4;
- }
- $this->form_validation->set_rules('customer', 'Customer', 'trim|required');
- if ($this->form_validation->run() == false) {
- $this->add();
- } else {
- $data = array(
- "po" => $this->input->post('so'),
- "po_cust" => $this->input->post('po_cust') ?: "",
- "cc_holder" => $this->input->post('taxx'),
- "currentdate" => $this->input->post('sales_date'),
- "date" => $this->input->post('cust_date'),
- "reference_no" => serialize($this->input->post('reference_no')),
- "ketnama" => $this->input->post('reference'),
- "warehouse_id" => "",
- "biller_id" => $this->input->post('biller_id'),
- "customer_id" => $this->input->post('customer'),
- "upcc" => $this->input->post('main'),
- "upcc2" => $this->input->post('cc'),
- "total" => $this->input->post('grand_total'),
- "discount_value" => $this->input->post('total_discount'),
- "tax_value" => $this->input->post('total_tax'),
- "note" => $this->input->post('note'),
- "shipping_city_id" => $this->input->post('city'),
- "shipping_state_id" => $this->input->post('state'),
- "shipping_country_id" => $this->input->post('country'),
- "shipping_address" => $this->input->post('address'),
- "shipping_charge" => $this->input->post('shipping_charge'),
- "internal_note" => $this->input->post('internal_note'),
- "mode_of_transport" => $this->input->post('mode_of_transport'),
- "transporter_name" => $this->input->post('transporter_name'),
- "transporter_code" => $this->input->post('transporter_code'),
- "vehicle_regn_no" => $this->input->post('vehicle_regn_no'),
- "l_r_no" => $this->input->post('l_r_no'),
- "chalan_no" => $this->input->post('chalan_no'),
- "indent_no" => $this->input->post('indent_no'),
- "credit_days" => $this->input->post('credit_days'),
- "date_of_supply" => $this->input->post('date_of_supply'),
- "electronic_ref_no" => $this->input->post('electronic_ref_no'),
- "gst_payable" => $this->input->post('gst_payable'),
- "broker" => $this->input->post('broker'),
- "user" => $this->session->userdata('user_id'),
- "term_and_condition" => $this->input->post('term_and_condition'),
- "user_name" => $this->session->userdata('identity'),
- "kurs_id" => $this->input->post('kursdata'),
- "nominalcurrency" => $this->input->post('grand_currency'),
- "ATTN" => $this->input->post('tax'),
- "shipto" => $this->input->post('shipto'),
- "billto" => $this->input->post('billto'),
- "dateestimate" => $this->input->post('dateestimate'),
- "salesdesc" => $this->input->post('others'),
- "paid_by" => $this->input->post('paymenterms') ?: 'cash',
- "diskonpersen" => $this->input->post('DiscountPersen'),
- "service_description" => $this->input->post('service_description'),
- "additional_description" => $this->input->post('additional_description'),
- "status_rev" => $status,
- "diskon" => $this->input->post('diskonfix')
- );
- $invoice = array(
- "invoice_no" => $this->sales_model->generateInvoiceNo(),
- "sales_amount" => $this->input->post('grand_total'),
- "invoice_date" => date('Y-m-d')
- );
- if ($sales_id = $this->sales_model->addModel($data, $invoice)) {
- $log_data = array(
- 'user_id' => $this->session->userdata('user_id'),
- 'table_id' => $sales_id,
- 'message' => 'Sales Inserted'
- );
- $this->log_model->insert_log($log_data);
- $jumlahtermin = $this->input->post('terminnumber');
- if (!empty($jumlahtermin)) {
- $termins = $this->input->post('terminvalue');
- $ket = $this->input->post('terminket');
- $tanggaltermins = $this->input->post('tanggalterminvalue');
- $i = 1;
- if (!empty($termins)) {
- $im = 0;
- $termino = 0;
- foreach ($termins as $quan) {
- $value = $this->input->post('grand_total');
- $nominal = ($value * $quan) / 100;
- $nominal = number_format((float) $nominal, 2, '.', '');
- if (!empty($tanggaltermins[$im])) {
- $datetermin = $tanggaltermins[$im];
- } else {
- $datetermin = date('Y-m-d');
- }
- $termino++;
- $datatermin = array(
- "sales_id" => $sales_id,
- "persen" => $quan,
- "nominal" => $nominal,
- "tanggalbayar" => $datetermin,
- "keterangan" => $ket[$i]
- );
- $this->sales_model->addTerminModel($datatermin);
- $i++;
- $im++;
- }
- } else {
- }
- }
- $js_data = json_decode($this->input->post('table_data'));
- $js_data1 = json_decode($this->input->post('tableadditional_data'));
- $js_data2 = json_decode($this->input->post('tableservice_data'));
- $js_data3 = json_decode($this->input->post('tableitemrequest'));
- // if ($js_data) {
- // foreach ($js_data as $key => $value) {
- // if ($value != null || !empty($value->product_id)) {
- // $data = array(
- // "product_id" => $value->product_id,
- // "quantity" => $value->quantity,
- // "price" => $value->price,
- // "gross_total" => $value->total,
- // "discount_id" => @$value->discount_id,
- // "discount_value" => @$value->discount_value,
- // "discount" => $value->discount,
- // "serial_no" => $value->desc,
- // "sales_id" => $sales_id
- // );
- // $this->db->insert('sales_items' ,$data);
- // }
- // }
- // }
- $product_id = $this->input->post('product_id');
- foreach ($product_id as $e=>$pd) {
- $quantity = $this->input->post('qty'.$e);
- $price = $this->input->post('price'.$e);
- $gross_total = $this->input->post('subtotal'.$e);
- $discount_id = $this->input->post('discount_id'.$e);
- $discount_value = $this->input->post('discount_value'.$e);
- $discount = $this->input->post('discount'.$e);
- $serial_no = $this->input->post('serial_no'.$e);
- $sales_id = $sales_id;
- $lines['quantity'] = $quantity;
- $lines['price'] = $price;
- $lines['gross_total'] = $gross_total;
- $lines['discount_id'] = $discount_id;
- $lines['discount_value'] = $discount_value;
- $lines['discount'] = $discount;
- $lines['serial_no'] = $serial_no;
- $lines['sales_id'] = $sales_id;
- $this->db->insert('sales_items' ,$lines);
- }
- if ($js_data1) {
- foreach ($js_data1 as $key => $value) {
- if ($value != null || !empty($value->additional_id)) {
- $data = array(
- "product_id" => $value->additional_id,
- "quantity" => $value->quantity,
- "price" => $value->price,
- "gross_total" => $value->total,
- "discount_id" => @$value->discount_id,
- "discount_value" => @$value->discount_value,
- "discount" => $value->discount,
- "desc" => $value->desc,
- "sales_id" => $sales_id
- );
- $this->db->insert('sales_additional_items' ,$data);
- }
- }
- }
- if ($js_data2) {
- foreach ($js_data2 as $key => $value) {
- if ($value != null || !empty($value->service_id)) {
- $data = array(
- "service_id" => $value->service_id,
- "quantity" => @$value->quantity?:0,
- "price" => @$value->price?:0,
- "gross_total" => $value->total,
- "discount_id" => @$value->discount_id,
- "discount_value" => @$value->discount_value,
- "discount" => $value->discount,
- "sales_id" => $sales_id
- );
- $this->sales_model->addSalesServiceItem($data);
- }
- }
- }
- if ($js_data3) {
- var_dump($js_data3);
- foreach ($js_data3 as $value) {
- var_dump($value->request_date);
- //random name item req
- $digits = 4;
- $rand = str_pad(rand(0, pow(10, $digits)-1), $digits, '0', STR_PAD_LEFT);
- $number = date("dm").$rand;
- $cek = $this->db->select('*')->from('item_request')->where('sales_id', $sales_id)->get()->result();
- var_dump($cek);
- if (empty($cek)) {
- $deadline = date('Y-m-d', strtotime('14 day', strtotime(date($value->request_date))));
- $params = array(
- 'request_number' => $number,
- 'request_date' => $value->request_date,
- 'request_deadline' => $deadline,
- 'reference' => $value->reference,
- 'sales_id' => $sales_id,
- 'request_for' => 'Sales'
- );
- $this->db->insert('item_request', $params);
- $id = $this->db->insert_id();
- } else {
- $id = $cek[0]->id_item_request;
- }
- $params = array(
- 'item_request_id' => $id,
- 'product_id' => $value->id_product,
- 'price' => $value->price,
- 'qty' => $value->qty
- );
- $this->db->insert('item_request_items', $params);
- }
- }
- redirect('sales/view/' . $sales_id);
- } else {
- redirect('sales', 'refresh');
- }
- }
- }
- public function revisiSales() {
- $id = $this->input->post('sales_id');
- $status_old = $this->input->post('status_old');
- date_default_timezone_set("Asia/Bangkok");
- $this->form_validation->set_rules('customer', 'Customer', 'trim|required');
- $submit = $this->input->post('submit');
- if ($submit == "Publish") {
- $status = 1;
- } else {
- $status = 4;
- }
- if ($this->form_validation->run() == false) {
- $this->revisi($id);
- } else {
- $data = array(
- "po" => $this->input->post('po'),
- "cc_holder" => $this->input->post('taxx'),
- "po_cust" => $this->input->post('po_cust'),
- "po_new" => $this->input->post('po_new'),
- "currentdate" => $this->input->post('salesdate'),
- "date" => $this->input->post('cust_date'),
- "ketnama" => $this->input->post('reference'),
- "reference_no" => serialize($this->input->post('reference_no')),
- "warehouse_id" => "",
- "customer_id" => $this->input->post('customer'),
- "upcc" => $this->input->post('main'),
- "upcc2" => $this->input->post('cc'),
- "total" => $this->input->post('grand_total'),
- "discount_value" => $this->input->post('total_discount'),
- "tax_value" => $this->input->post('total_tax'),
- "note" => $this->input->post('note'),
- "shipping_city_id" => $this->input->post('city'),
- "shipping_state_id" => $this->input->post('state'),
- "shipping_country_id" => $this->input->post('country'),
- "shipping_address" => $this->input->post('address'),
- "shipping_charge" => $this->input->post('shipping_charge'),
- "internal_note" => $this->input->post('internal_note'),
- "mode_of_transport" => $this->input->post('mode_of_transport'),
- "transporter_name" => $this->input->post('transporter_name'),
- "transporter_code" => $this->input->post('transporter_code'),
- "vehicle_regn_no" => $this->input->post('vehicle_regn_no'),
- "l_r_no" => $this->input->post('l_r_no'),
- "chalan_no" => $this->input->post('chalan_no'),
- "indent_no" => $this->input->post('indent_no'),
- "credit_days" => $this->input->post('credit_days'),
- "date_of_supply" => $this->input->post('date_of_supply'),
- "electronic_ref_no" => $this->input->post('electronic_ref_no'),
- "gst_payable" => $this->input->post('gst_payable'),
- "broker" => $this->input->post('broker'),
- "user" => $this->session->userdata('user_id'),
- "term_and_condition" => $this->input->post('term_and_condition'),
- "user_name" => $this->session->userdata('identity'),
- "kurs_id" => $this->input->post('kursdata'),
- "nominalcurrency" => $this->input->post('grand_currency'),
- "ATTN" => $this->input->post('tax'),
- "shipto" => $this->input->post('shipto'),
- "billto" => $this->input->post('billto'),
- "dateestimate" => $this->input->post('dateestimate'),
- "salesdesc" => $this->input->post('others'),
- "paid_by" => $this->input->post('paymenterms') ?: 'advance',
- "additional_description" => $this->input->post('additional_description'),
- "service_description" => $this->input->post('service_description'),
- "diskonpersen" => $this->input->post('DiscountPersen'),
- "status_rev" => $status,
- "diskon" => $this->input->post('diskonfix')
- );
- $invoice = array(
- "invoice_no" => $this->sales_model->generateInvoiceNo(),
- "sales_amount" => $this->input->post('grand_total'),
- "invoice_date" => date('Y-m-d')
- );
- if ($sales_id = $this->sales_model->addModel($data, $invoice)) {
- if ($status_old == 2) {
- $product_items = $this->db->select('*')
- ->from('sales_items')
- ->where('sales_id', $id)
- ->get()
- ->result();
- foreach ($product_items as $row) {
- $idp = $this->db->select('*')
- ->from('product_grouping')
- ->where('product_id', $row->product_id)
- ->get()
- ->result();
- if ($idp) {
- $arlist = json_encode(unserialize($idp[0]->list));
- $arlist = json_decode($arlist);
- for ($ilist = 0; $ilist < count($arlist); $ilist++) {
- $quantity = $row->quantity * $arlist[$ilist]->ql;
- $this->db->set('quantity', 'quantity'-$quantity)
- ->where('product_id', $arlist[$ilist]->pl)
- ->update('products');
- }
- } else {
- $this->db->query("UPDATE products SET quantity=quantity + $row->quantity WHERE product_id=$row->product_id");
- }
- }
- $additional_items = $this->db->select('*')
- ->from('sales_additional_items')
- ->where('sales_id', $id)
- ->get()
- ->result();
- foreach ($additional_items as $value) {
- $idp = $this->db->select('*')
- ->from('product_grouping')
- ->where('product_id', $value->product_id)
- ->get()
- ->result();
- if ($idp) {
- $arlist = json_encode(unserialize($idp[0]->list));
- $arlist = json_decode($arlist);
- for ($ilist = 0; $ilist < count($arlist); $ilist++) {
- $quantity = $value->quantity * $arlist[$ilist]->ql;
- $this->db->set('quantity', 'quantity'-$quantity)
- ->where('product_id', $arlist[$ilist]->pl)
- ->update('products');
- }
- } else {
- $this->db->query("UPDATE products SET quantity=quantity + $row->quantity WHERE product_id=$value->product_id");
- }
- }
- }
- $log_data = array(
- 'user_id' => $this->session->userdata('user_id'),
- 'table_id' => $sales_id,
- 'message' => 'Sales Inserted'
- );
- $this->log_model->insert_log($log_data);
- $jumlahtermin = $this->input->post('terminnumber');
- if (!empty($jumlahtermin)) {
- $termins = $this->input->post('terminvalue');
- $ket = $this->input->post('terminket');
- $tanggaltermins = $this->input->post('tanggalterminvalue');
- $i = 1;
- if (!empty($termins)) {
- $im = 0;
- $termino = 0;
- foreach ($termins as $quan) {
- $value = $this->input->post('grand_total');
- $nominal = ($value * $quan) / 100;
- $nominal = number_format((float) $nominal, 2, '.', '');
- if (!empty($tanggaltermins[$im])) {
- $datetermin = $tanggaltermins[$im];
- } else {
- $datetermin = date('Y-m-d');
- }
- $termino++;
- $datatermin = array(
- "sales_id" => $sales_id,
- "persen" => $quan,
- "nominal" => $nominal,
- "tanggalbayar" => $datetermin,
- "keterangan" => $ket[$i]
- );
- $this->sales_model->addTerminModel($datatermin);
- $i++;
- $im++;
- }
- }
- }
- $js_data = json_decode($this->input->post('table_data'));
- $js_data1 = json_decode($this->input->post('tableadditional_data'));
- $js_data2 = json_decode($this->input->post('tableservice_data'));
- foreach ($js_data as $key => $value) {
- if ($value != null || !empty($value->product_id)) {
- $data = array(
- "product_id" => $value->product_id,
- "quantity" => $value->quantity,
- "price" => $value->price,
- "gross_total" => $value->total,
- "discount_id" => @$value->discount_id,
- "discount_value" => @$value->discount_value,
- "discount" => $value->discount,
- "serial_no" => $value->desc,
- "sales_id" => $sales_id
- );
- $this->db->insert('sales_items', $data);
- }
- }
- foreach ($js_data1 as $key => $value) {
- if ($value != null || !empty($value->additional_id)) {
- $data = array(
- "product_id" => $value->additional_id,
- "quantity" => $value->quantity,
- "price" => $value->price,
- "gross_total" => $value->total,
- "discount_id" => @$value->discount_id,
- "discount_value" => @$value->discount_value,
- "discount" => $value->discount,
- "desc" => $value->desc,
- "sales_id" => $sales_id
- );
- $this->db->insert('sales_additional_items' ,$data);
- }
- }
- if (!empty($js_data2)) {
- foreach ($js_data2 as $key => $value) {
- if ($value != null || !empty($value->service_id)) {
- $data = array(
- "service_id" => $value->service_id,
- "quantity" => $value->quantity,
- "price" => $value->price,
- "gross_total" => $value->total,
- "discount_id" => @$value->discount_id,
- "discount_value" => @$value->discount_value,
- "discount" => $value->discount,
- "sales_id" => $sales_id
- );
- $this->sales_model->addSalesServiceItem($data);
- }
- }
- }
- $dataman = array(
- "status_rev" => 2
- );
- if ($this->sales_model->editModel($id, $dataman)) {
- $log_data = array(
- 'user_id' => $this->session->userdata('user_id'),
- 'table_id' => $id,
- 'message' => 'Change Revisi Sales Updated'
- );
- $this->log_model->insert_log($log_data);
- }
- redirect('sales/view/' . $sales_id);
- } else {
- redirect('sales', 'refresh');
- }
- }
- }
- /*
- call edit view to edit sales record
- */
- public function getCurrencyAjax($id) {
- $data = $this->sales_model->getCurrencyId($id);
- echo json_encode($data);
- //print_r($data);
- }
- public function disetujui($id) {
- $data['data'] = $this->sales_model->getDetails($id);
- $data['quotation'] = $this->quotation_model->getQuotation();
- $data['check_invoice'] = $this->sales_model->checkInvoice($id);
- $data['items'] = $this->sales_model->getItems($id);
- $data['serviceitems'] = $this->sales_model->getServiceItems($id);
- $data['company'] = $this->purchase_model->getCompany();
- $data['customer'] = $this->customer_model->getRecord($data['data'][0]->customer_id);
- $data['quotationadditional'] = $this->quotation_model->getAdditional($id);
- $this->load->view('sales/disetujui', $data);
- }
- public function changeSetujui() {
- $id = $this->input->post('sales_id');
- $this->form_validation->set_rules('status', 'Status', 'required');
- if ($this->form_validation->run() == false) {
- $this->disetujui($id);
- } else {
- $data = array(
- 'status_rev' => 2
- );
- $array['id_medrep'] = $this->input->post("id_medrep");
- $array['id_sales'] = $this->input->post("id_sales");
- $array['total_sales'] = $this->input->post("total_sales");
- $this->sales_model->insert('medrep_transection',$array);
- $product_items = $this->db->select('*')
- ->from('sales_items')
- ->where('sales_id', $id)
- ->get()
- ->result();
- foreach ($product_items as $row) {
- $idp = $this->db->select('*')
- ->from('product_grouping')
- ->where('product_id', $row->product_id)
- ->get()
- ->result();
- if ($idp) {
- $arlist = json_encode(unserialize($idp[0]->list));
- $arlist = json_decode($arlist);
- for ($ilist = 0; $ilist < count($arlist); $ilist++) {
- $quantity = $row->quantity * $arlist[$ilist]->ql;
- $this->db->set('quantity', 'quantity'-$quantity)
- ->where('product_id', $arlist[$ilist]->pl)
- ->update('products');
- }
- } else {
- $this->db->query("UPDATE products SET quantity=quantity - $row->quantity WHERE product_id=$row->product_id");
- }
- }
- $additional_items = $this->db->select('*')
- ->from('sales_additional_items')
- ->where('sales_id', $id)
- ->get()
- ->result();
- foreach ($additional_items as $value) {
- $idp = $this->db->select('*')
- ->from('product_grouping')
- ->where('product_id', $value->product_id)
- ->get()
- ->result();
- if ($idp) {
- $arlist = json_encode(unserialize($idp[0]->list));
- $arlist = json_decode($arlist);
- for ($ilist = 0; $ilist < count($arlist); $ilist++) {
- $quantity = $value->quantity * $arlist[$ilist]->ql;
- $this->db->set('quantity', 'quantity'-$quantity)
- ->where('product_id', $arlist[$ilist]->pl)
- ->update('products');
- }
- } else {
- $this->db->query("UPDATE products SET quantity=quantity - $row->quantity WHERE product_id=$value->product_id");
- }
- }
- $update = $this->db->where('sales_id', $id)->update('sales', $data);
- if ($update) {
- $log_data = array(
- 'user_id' => $this->session->userdata('user_id'),
- 'table_id' => $id,
- 'message' => 'Change Setujui Sales Updated'
- );
- $this->log_model->insert_log($log_data);
- redirect('sales', 'refresh');
- } else {
- redirect('sales', 'refresh');
- }
- }
- }
- public function ditolak($id) {
- $data['data'] = $this->sales_model->getDetails($id);
- $data['quotation'] = $this->quotation_model->getQuotation();
- $data['check_invoice'] = $this->sales_model->checkInvoice($id);
- $data['items'] = $this->sales_model->getItems($id);
- $data['serviceitems'] = $this->sales_model->getServiceItems($id);
- $data['company'] = $this->purchase_model->getCompany();
- $data['customer'] = $this->customer_model->getRecord($data['data'][0]->customer_id);
- $data['quotationadditional'] = $this->quotation_model->getAdditional($id);
- $this->load->view('sales/ditolak', $data);
- }
- public function changeTolak() {
- $id = $this->input->post('sales_id');
- $this->form_validation->set_rules('status', 'Status', 'required');
- $this->form_validation->set_rules('ditolak', 'Keterangan Ditolak', 'required');
- if ($this->form_validation->run() == false) {
- $this->ditolak($id);
- } else {
- $data = array(
- 'status_rev' => 3
- );
- $update = $this->db->where('sales_id', $id)->update('sales', $data);
- if ($update) {
- $log_data = array(
- 'user_id' => $this->session->userdata('user_id'),
- 'table_id' => $id,
- 'message' => 'Change Ditolak Sales Updated'
- );
- $this->log_model->insert_log($log_data);
- redirect('sales', 'refresh');
- } else {
- redirect('sales', 'refresh');
- }
- }
- }
- public function edit($id) {
- $kursdata = $this->company_setting_model->getCurrency();
- $data['brands'] = $this->brand_model->getBrand();
- $data['customer'] = $this->sales_model->getCustomer();
- $data['biller'] = $this->sales_model->getBiller();
- $data['product2'] = $this->sales_model->getProducts2();
- $data['service'] = $this->sales_model->getService();
- $data['additional'] = $this->sales_model->getAdditional($id);
- $data['discount'] = $this->sales_model->getDiscount();
- $data['bonus'] = $this->sales_model->getBonus($id);
- $data['tax'] = $this->sales_model->getTax();
- $data['data'] = $this->sales_model->getRecord($id);
- $data['country'] = $this->customer_model->getCountry();
- $data['kursdata'] = $kursdata;
- $data['state'] = $this->customer_model->getState($data['data'][0]->shipping_country_id);
- $data['city'] = $this->customer_model->getCity($data['data'][0]->shipping_state_id);
- $data['product'] = $this->sales_model->getProducts($data['data'][0]->warehouse_id);
- $data['items'] = $this->sales_model->getSalesItems($id);
- $data['serviceitems'] = $this->sales_model->getServiceItems($data['data'][0]->sales_id);
- $data['termin'] = $this->sales_model->getTerminSalesId($data['data'][0]->sales_id);
- $this->load->view('sales/edit', $data);
- }
- public function revisi($id) {
- $kursdata = $this->company_setting_model->getCurrency();
- $data['brands'] = $this->brand_model->getBrand();
- $data['biller'] = $this->sales_model->getBiller();
- $data['customer'] = $this->sales_model->getCustomer();
- $data['product2'] = $this->sales_model->getProducts2();
- $data['service'] = $this->sales_model->getService();
- $data['additional'] = $this->sales_model->getAdditional($id);
- $data['discount'] = $this->sales_model->getDiscount();
- $data['tax'] = $this->sales_model->getTax();
- $data['data'] = $this->sales_model->getRecord($id);
- $data['country'] = $this->customer_model->getCountry();
- $data['kursdata'] = $kursdata;
- $data['state'] = $this->customer_model->getState($data['data'][0]->shipping_country_id);
- $data['city'] = $this->customer_model->getCity($data['data'][0]->shipping_state_id);
- $data['product'] = $this->sales_model->getProducts($data['data'][0]->warehouse_id);
- $data['items'] = $this->sales_model->getSalesItems($data['data'][0]->sales_id);
- $data['serviceitems'] = $this->sales_model->getServiceItems($data['data'][0]->sales_id);
- $data['termin'] = $this->sales_model->getTerminSalesId($data['data'][0]->sales_id);
- $this->load->view('sales/revisi', $data);
- }
- /*
- this fucntion is to edit sales record and save in database
- */
- public function editSales() {
- $id = $this->input->post('sales_id');
- $submit = $this->input->post('submit');
- if ($submit == "Update") {
- $status = 0;
- } else {
- $status = 4;
- }
- $this->form_validation->set_rules('customer', 'Customer', 'trim|required');
- if ($this->form_validation->run() == false) {
- $this->edit($id);
- } else {
- $warehouse_id = $this->input->post('warehouse');
- $old_warehouse_id = $this->input->post('old_warehouse_id');
- $warehouse_change = $this->input->post('warehouse_change');
- $data = array(
- "currentdate" => $this->input->post('sales_date'),
- "date" => $this->input->post('cust_date'),
- "cc_holder" => $this->input->post('taxx'),
- "po_cust" => $this->input->post('po_cust'),
- "warehouse_id" => $this->input->post('warehouse'),
- "ketnama" => $this->input->post('reference'),
- "biller_id" => $this->input->post('biller_id'),
- "customer_id" => $this->input->post('customer'),
- "upcc" => $this->input->post('main'),
- "upcc2" => $this->input->post('cc'),
- "total" => $this->input->post('grand_total'),
- "discount_value" => $this->input->post('total_discount'),
- "tax_value" => $this->input->post('total_tax'),
- "note" => $this->input->post('note'),
- "shipping_city_id" => $this->input->post('city'),
- "shipping_state_id" => $this->input->post('state'),
- "shipping_country_id" => $this->input->post('country'),
- "shipping_address" => $this->input->post('address'),
- "shipping_charge" => $this->input->post('shipping_charge'),
- "internal_note" => $this->input->post('internal_note'),
- "mode_of_transport" => $this->input->post('mode_of_transport'),
- "transporter_name" => $this->input->post('transporter_name'),
- "transporter_code" => $this->input->post('transporter_code'),
- "vehicle_regn_no" => $this->input->post('vehicle_regn_no'),
- "l_r_no" => $this->input->post('l_r_no'),
- "chalan_no" => $this->input->post('chalan_no'),
- "indent_no" => $this->input->post('indent_no'),
- "credit_days" => $this->input->post('credit_days'),
- "date_of_supply" => $this->input->post('date_of_supply'),
- "electronic_ref_no" => $this->input->post('electronic_ref_no'),
- "gst_payable" => $this->input->post('gst_payable'),
- "broker" => $this->input->post('broker'),
- "user" => $this->session->userdata('user_id'),
- "term_and_condition" => $this->input->post('term_and_condition'),
- "sales_id" => $this->input->post('sales_id'),
- "user_name" => $this->session->userdata('identity'),
- "kurs_id" => $this->input->post('kursdata'),
- "nominalcurrency" => $this->input->post('grand_currency'),
- "ATTN" => $this->input->post('tax'),
- "shipto" => $this->input->post('shipto'),
- "billto" => $this->input->post('billto'),
- "dateestimate" => $this->input->post('dateestimate'),
- "salesdesc" => $this->input->post('others'),
- "paid_by" => $this->input->post('paymenterms') ?: 'advance',
- "additional_description" => $this->input->post('additional_description'),
- "service_description" => $this->input->post('service_description'),
- "diskonpersen" => $this->input->post('DiscountPersen'),
- "diskon" => $this->input->post('diskonfix'),
- "status_rev" => $status
- );
- if ($this->sales_model->editModel($id, $data)) {
- $log_data = array(
- 'user_id' => $this->session->userdata('user_id'),
- 'table_id' => $id,
- 'message' => 'Sales Updated'
- );
- $this->log_model->insert_log($log_data);
- $this->sales_model->deleteTerminModel($id);
- $jumlahtermin = $this->input->post('terminnumber');
- if (!empty($jumlahtermin)) {
- $termins = $this->input->post('terminvalue');
- $tanggaltermins = $this->input->post('tanggalterminvalue');
- $ket = $this->input->post('terminket');
- if (!empty($termins)) {
- $im = 0;
- $i = 1;
- foreach ($termins as $quan) {
- $value = $this->input->post('grand_total');
- $nominal = ($value * $quan) / 100;
- $nominal = number_format((float) $nominal, 2, '.', '');
- if (!empty($tanggaltermins[$im])) {
- $datetermin = $tanggaltermins[$im];
- } else {
- $datetermin = date('Y-m-d');
- }
- $datatermin = array(
- "sales_id" => $id,
- "persen" => $quan,
- "nominal" => $nominal,
- "tanggalbayar" => $datetermin,
- "keterangan" => $ket[$i]
- );
- $this->sales_model->addTerminModel($datatermin);
- $i++;
- $im++;
- }
- } else {
- }
- }
- $this->sales_model->deleteSalesItemsAll($id);
- $js_data = json_decode($this->input->post('table_data'));
- $js_data1 = json_decode($this->input->post('tableadditional_data'));
- $js_data2 = json_decode($this->input->post('tableservice_data'));
- foreach ($js_data as $key => $value) {
- if (!empty($value) and ! empty($value->product_id)) {
- $data = array(
- "product_id" => $value->product_id,
- "quantity" => (!empty($value->quantity)) ? $value->quantity : 0,
- "price" => (!empty($value->price)) ? $value->price : 0,
- "gross_total" => (!empty($value->total)) ? $value->total : 0,
- "discount_id" => (!empty(@$value->discount_id)) ? @$value->discount_id : 0,
- "discount_value" => (!empty(@$value->discount_value)) ? @$value->discount_value : 0,
- "discount" => (!empty($value->discount)) ? $value->discount : 0,
- "serial_no" => (!empty($value->desc)) ? $value->desc : 0,
- "sales_id" => $id
- );
- $this->db->insert('sales_items', $data);
- }
- }
- $this->sales_model->deleteSalesAdditionalAll($id);
- foreach ($js_data1 as $key => $value) {
- if ($value != null || !empty($value->additional_id)) {
- $data = array(
- "product_id" => $value->additional_id,
- "quantity" => $value->quantity,
- "price" => $value->price,
- "gross_total" => $value->total,
- "discount_id" => @$value->discount_id,
- "discount_value" => @$value->discount_value,
- "discount" => $value->discount,
- "desc" => $value->desc,
- "sales_id" => $id
- );
- $this->db->insert('sales_additional_items' ,$data);
- }
- }
- $this->sales_model->deleteSalesServiceItemsAll($id);
- if (!empty($js_data2)) {
- foreach ($js_data2 as $key => $value) {
- if ($value != null || !empty($value->service_id)) {
- $data = array(
- "service_id" => $value->service_id,
- "quantity" => $value->quantity,
- "price" => $value->price,
- "gross_total" => $value->total,
- "discount_id" => @$value->discount_id,
- "discount_value" => @$value->discount_value,
- "discount" => $value->discount,
- "sales_id" => $id
- );
- $this->sales_model->addSalesServiceItem($data);
- }
- }
- }
- redirect('sales/view/' . $id);
- } else {
- redirect('sales', 'refresh');
- }
- }
- }
- /*
- this function is used to delete sales record from database
- */
- public function delete($id) {
- if ($this->sales_model->deleteModel($id)) {
- $log_data = array(
- 'user_id' => $this->session->userdata('user_id'),
- 'table_id' => $id,
- 'message' => 'Sales Deleted'
- );
- $this->log_model->insert_log($log_data);
- redirect('sales', 'refresh');
- } else {
- redirect('sales', 'refresh');
- }
- }
- /*
- display data in dashboard calendar
- */
- public function calendar() {
- log_message('debug', print_r($this->db->get('category')->result(), true));
- $data = $this->sales_model->getCalendarData();
- $total = 0;
- foreach ($data as $value) {
- $date = Date('Y-m-d');
- if ($date == $value->date) {
- $total += $value->total;
- }
- $temp = array(
- "title" => $total,
- "start" => "2017-04-05T00:01:00+05:30"
- );
- }
- echo json_encode($temp);
- }
- /*
- view Sales details
- */
- public function view($id) {
- $data['quotation'] = $this->quotation_model->getQuotation();
- $data['data'] = $this->sales_model->getDetails($id);
- $data['items'] = $this->sales_model->getItems($id);
- $data['symbol'] = $this->db->select('*')->from("currency")->where("kurs_id", $data['data'][0]->kurs_id)->get()->result()[0]->symbol;
- for ($i=0; $i < count($data['items']) ; $i++) {
- if ($data['items'][$i]->product_grouping != NULL) {
- $arlist = json_encode(unserialize($data['items'][$i]->list));
- $arlist = json_decode($arlist);
- $max = array();
- for ($ilist = 0; $ilist < count($arlist); $ilist++) {
- $qtyp = $this->db->select('quantity')->from('products')->where('product_id', $arlist[$ilist]->pl)->get()->result()[0]->quantity;
- $count = ($qtyp / intval($arlist[$ilist]->ql));
- array_push($max, $count);
- }
- $min = min($max);
- $data['items'][$i]->quantity_product = intval($min);
- }
- }
- $data['additional'] = $this->sales_model->getAdditional($id);
- for ($i=0; $i < count($data['additional']) ; $i++) {
- if ($data['additional'][$i]->product_grouping != NULL) {
- $arlist = json_encode(unserialize($data['additional'][$i]->list));
- $arlist = json_decode($arlist);
- $max = array();
- for ($ilist = 0; $ilist < count($arlist); $ilist++) {
- $qtyp = $this->db->select('quantity')->from('products')->where('product_id', $arlist[$ilist]->pl)->get()->result()[0]->quantity;
- $count = ($qtyp / intval($arlist[$ilist]->ql));
- array_push($max, $count);
- }
- $min = min($max);
- $data['additional'][$i]->quantity_product = intval($min);
- }
- }
- $data['serviceitems'] = $this->sales_model->getServiceItems($data['data'][0]->sales_id);
- $data['company'] = $this->purchase_model->getCompany();
- $data['salestermins'] = $this->sales_model->getTerminSalesId($id);
- $this->load->view('sales/view', $data);
- }
- /*
- generate pdf
- */
- public function pdf($id) {
- $log_data = array(
- 'user_id' => $this->session->userdata('user_id'),
- 'table_id' => $id,
- 'message' => 'Invoice Generated'
- );
- $this->log_model->insert_log($log_data);
- ob_start();
- $html = ob_get_clean();
- $html = utf8_encode($html);
- $data['quotation'] = $this->quotation_model->getQuotation();
- $data['data'] = $this->sales_model->getDetails($id);
- $data['items'] = $this->sales_model->getItems($id);
- for ($i=0; $i < count($data['items']) ; $i++) {
- if ($data['items'][$i]->product_grouping != NULL) {
- $arlist = json_encode(unserialize($data['items'][$i]->list));
- $arlist = json_decode($arlist);
- $array = array();
- for ($ilist = 0; $ilist < count($arlist); $ilist++) {
- $name = $this->db->select('name')->from('products')->where('product_id', $arlist[$ilist]->pl)->get()->result()[0]->name;
- array_push($array, $name);
- }
- $list = implode(', ', $array);
- $data['items'][$i]->name = $data['items'][$i]->name. ' : ' .$list;
- }
- }
- $data['serviceitems'] = $this->sales_model->getServiceItems($data['data'][0]->sales_id);
- $data['company'] = $this->purchase_model->getCompany();
- $data['company_setting'] = $this->company_setting_model->getData();
- $data['signature'] = $this->signature_model->getActiveSignature();
- $data['customer'] = $this->customer_model->getRecord($data['data'][0]->customer_id);
- $data['customer_shipto'] = $this->customer_model->getCustomerAddressbyID($data['data'][0]->shipto);
- $data['additional'] = $this->sales_model->getAdditional($id);
- $data['salestermins'] = $this->sales_model->getTerminSalesId($id);
- for ($i=0; $i < count($data['additional']) ; $i++) {
- if ($data['additional'][$i]->product_grouping != NULL) {
- $arlist = json_encode(unserialize($data['additional'][$i]->list));
- $arlist = json_decode($arlist);
- $array = array();
- for ($ilist = 0; $ilist < count($arlist); $ilist++) {
- $name = $this->db->select('name')->from('products')->where('product_id', $arlist[$ilist]->pl)->get()->result()[0]->name;
- array_push($array, $name);
- }
- $list = implode(', ', $array);
- $data['additional'][$i]->name = $data['additional'][$i]->name. ' : ' .$list;
- }
- }
- $data['bank'] = $this->bank_model->getRecordAr();
- $data['customer_billto'] = $this->customer_model->getCustomerAddressbyID($data['data'][0]->billto);
- $data['symbol'] = $this->db->select('*')->from("currency")->where("kurs_id", $data['data'][0]->kurs_id)->get()->result()[0]->symbol;
- // UNTUK FONT
- $t = 0;
- foreach ($data['items'] as $value) { $t += ($value->price * $value->quantity); }
- foreach ($data['additional'] as $value) { $t += $value->gross_total; }
- foreach ($data['serviceitems'] as $value) { $t += ($value->price * $value->quantity); }
- $r = $t - $data['data'][0]->discount_value + $data['data'][0]->shipping_charge + $data['data'][0]->tax_value;
- if ($r > $t) {
- $font = $r;
- } else {
- $font = $t;
- }
- if(strlen($font) <= 9) {
- $data['style'] = 'style="font-size: 9pt"';
- $data['style2'] = 'style="font-size: 8pt; font-style: italic; font-weight: bold;"';
- } elseif (strlen($font) == 10) {
- $data['style'] = 'style="font-size: 8pt"';
- $data['style2'] = 'style="font-size: 7pt; font-style: italic; font-weight: bold;"';
- } elseif (strlen($font) >= 11) {
- $data['style'] = 'style="font-size: 7pt"';
- $data['style2'] = 'style="font-size: 6pt; font-style: italic; font-weight: bold;"';
- }
- $html = $this->load->view('sales/pdf', $data, true);
- $logo = base_url(header_logo('logo'));
- $width = header_logo('width');
- $height = header_logo('height');
- $mpdf = new \Mpdf\Mpdf(['setAutoTopMargin' => 'stretch', 'format' => [216, 356]]);
- $mpdf->SetHTMLHeader('
- <table style=" vertical-align: bottom; font-family: serif; font-size: 9pt;" width="100%">
- <tr>
- <td width="40%" valign="top"><img src="'. $logo .'" width="'. $width .'" height="'. $height .'"></td>
- <td style="text-align: right;" width="60%">
- '.header_doc() . '
- </td>
- </tr>
- </table>');
- if ($data['data'][0]->status_rev == 4) {
- $status = 'Draft';
- $mpdf->SetWatermarkText($status);
- $mpdf->showWatermarkText = true;
- } else {
- $mpdf->SetWatermarkImage(base_url('/assets/images/logo-glodisa.jpg'));
- $mpdf->showWatermarkImage = true;
- }
- $mpdf->allow_charset_conversion = true;
- $mpdf->setFooter('|page {PAGENO} of {nbpg}|');
- $mpdf->charset_in = 'UTF-8';
- $mpdf->use_kwt = true;
- $mpdf->WriteHTML($html);
- $mpdf->Output(($data['data'][0]->po_new ?: $data['data'][0]->po) . '.pdf', 'I');
- }
- public function word($id, $ida='1') {
- $idar = str_replace('_', ',', $ida);
- $log_data = array(
- 'user_id' => $this->session->userdata('user_id'),
- 'table_id' => $id,
- 'message' => 'Invoice Generated'
- );
- $this->log_model->insert_log($log_data);
- ob_start();
- $html = ob_get_clean();
- $html = utf8_encode($html);
- $data['quotation'] = $this->quotation_model->getQuotation();
- $data['data'] = $this->sales_model->getDetails($id);
- $data['items'] = $this->sales_model->getItems($id);
- for ($i=0; $i < count($data['items']) ; $i++) {
- if ($data['items'][$i]->product_grouping != NULL) {
- $arlist = json_encode(unserialize($data['items'][$i]->list));
- $arlist = json_decode($arlist);
- $array = array();
- for ($ilist = 0; $ilist < count($arlist); $ilist++) {
- $name = $this->db->select('name')->from('products')->where('product_id', $arlist[$ilist]->pl)->get()->result()[0]->name;
- array_push($array, $name);
- }
- $list = implode(', ', $array);
- $data['items'][$i]->name = $data['items'][$i]->name. ' : ' .$list;
- }
- }
- $data['serviceitems'] = $this->sales_model->getServiceItems($data['data'][0]->sales_id);
- $data['company'] = $this->purchase_model->getCompany();
- $data['company_setting'] = $this->company_setting_model->getData();
- $data['signature'] = $this->signature_model->getActiveSignature();
- $data['customer'] = $this->customer_model->getRecord($data['data'][0]->customer_id);
- $data['customer_shipto'] = $this->customer_model->getCustomerAddressbyID($data['data'][0]->shipto);
- $data['additional'] = $this->sales_model->getAdditional($id);
- $data['salestermins'] = $this->sales_model->getTerminSalesId($id);
- for ($i=0; $i < count($data['additional']) ; $i++) {
- if ($data['additional'][$i]->product_grouping != NULL) {
- $arlist = json_encode(unserialize($data['additional'][$i]->list));
- $arlist = json_decode($arlist);
- $array = array();
- for ($ilist = 0; $ilist < count($arlist); $ilist++) {
- $name = $this->db->select('name')->from('products')->where('product_id', $arlist[$ilist]->pl)->get()->result()[0]->name;
- array_push($array, $name);
- }
- $list = implode(', ', $array);
- $data['additional'][$i]->name = $data['additional'][$i]->name. ' : ' .$list;
- }
- }
- $data['bank'] = $this->bank_model->getRecordAr();
- $data['customer_billto'] = $this->customer_model->getCustomerAddressbyID($data['data'][0]->billto);
- $data['symbol'] = $this->db->select('*')->from("currency")->where("kurs_id", $data['data'][0]->kurs_id)->get()->result()[0]->symbol;
- // UNTUK FONT
- $t = 0;
- foreach ($data['items'] as $value) { $t += ($value->price * $value->quantity); }
- foreach ($data['additional'] as $value) { $t += $value->gross_total; }
- foreach ($data['serviceitems'] as $value) { $t += ($value->price * $value->quantity); }
- $r = $t - $data['data'][0]->discount_value + $data['data'][0]->shipping_charge + $data['data'][0]->tax_value;
- if ($r > $t) {
- $font = $r;
- } else {
- $font = $t;
- }
- if(strlen($font) <= 9) {
- $data['style'] = 'style="font-size: 9pt"';
- $data['style2'] = 'style="font-size: 8pt; font-style: italic; font-weight: bold;"';
- } elseif (strlen($font) == 10) {
- $data['style'] = 'style="font-size: 8pt"';
- $data['style2'] = 'style="font-size: 7pt; font-style: italic; font-weight: bold;"';
- } elseif (strlen($font) >= 11) {
- $data['style'] = 'style="font-size: 7pt"';
- $data['style2'] = 'style="font-size: 6pt; font-style: italic; font-weight: bold;"';
- }
- $this->load->library('lmsword');
- $this->lmsword->page_setup('A4');
- $this->lmsword->html($this->load->view('sales/pdf', $data, true));
- $this->lmsword->create($data['data'][0]->po_new ?: $data['data'][0]->po);
- }
- public function print1($id, $idb='1') {
- $idar = str_replace('_', ',', $idb);
- $log_data = array(
- 'user_id' => $this->session->userdata('user_id'),
- 'table_id' => $id,
- 'message' => 'Invoice Printed'
- );
- $this->log_model->insert_log($log_data);
- $data['data'] = $this->sales_model->getDetails($id);
- $data['items'] = $this->sales_model->getItems($id);
- $data['company'] = $this->purchase_model->getCompany();
- $data['quotation'] = $this->quotation_model->getQuotation();
- $data['data'] = $this->sales_model->getDetails($id);
- $data['bank'] = $this->bank_model->getRecordAr($idar);
- $data['additional'] = $this->sales_model->getAdditional($id);
- $data['items'] = $this->sales_model->getItems($id);
- $data['serviceitems'] = $this->sales_model->getServiceItems($data['data'][0]->sales_id);
- $data['company'] = $this->purchase_model->getCompany();
- $data['company_setting'] = $this->company_setting_model->getData();
- $data['signature'] = $this->signature_model->getActiveSignature();
- $data['customer'] = $this->customer_model->getRecord($data['data'][0]->customer_id);
- $data['customer_shipto'] = $this->customer_model->getCustomerAddressbyID($data['data'][0]->shipto);
- $data['customer_billto'] = $this->customer_model->getCustomerAddressbyID($data['data'][0]->billto);
- $this->load->view('sales/pdf', $data);
- }
- /*
- send email
- */
- public function email($id) {
- $log_data = array(
- 'user_id' => $this->session->userdata('user_id'),
- 'table_id' => 0,
- 'message' => 'Invoice Email Send'
- );
- $this->log_model->insert_log($log_data);
- $email = $this->sales_model->getSmtpSetup();
- $data = $this->sales_model->getCustomerEmail($id);
- $company = $this->purchase_model->getCompany();
- $this->load->view('class.phpmailer.php');
- $mail = new PHPMailer();
- $mail->IsSMTP();
- $mail->Host = $email->smtp_host;
- $mail->SMTPAuth = true;
- //$mail->SMTPSecure = "ssl";
- $mail->Port = $email->smtp_port;
- $mail->Username = $email->smtp_username;
- $mail->Password = $email->smtp_password;
- $mail->From = $email->from_address;
- $mail->FromName = $email->from_name;
- $mail->AddAddress($data[0]->email);
- //$mail->AddReplyTo("mail@mail.com");
- /* $mail->IsHTML(true);
- $mail->Subject = "Purchase order No : ".$data[0]->reference_no." From ".$company[0]->name;
- $mail->Body = "Date : ".$data[0]->date."<br>Total : ".$data[0]->total;
- //$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
- if(!$mail->Send())
- {
- $message = "Email could not be sent";
- }
- else{
- $message = "Email has been sent";
- } */
- $total = $data[0]->total + $data[0]->shipping_charge;
- $this->load->library('email');
- $this->email->from($email->from_address, $email->from_name);
- $this->email->to($data[0]->email);
- $this->email->subject("Sales order No : " . $data[0]->reference_no . " From " . $company[0]->name);
- $this->email->message("Date : " . $data[0]->date . " \nTotal : " . $total . " \n\n\nComapany Name : " . $company[0]->name . "\nAddress : " . $company[0]->street . " " . $company[0]->country_name . "\nMobile No :" . $company[0]->phone);
- //Send mail
- if ($this->email->send())
- $message = "Email sent successfully.";
- else
- $message = "Error in sending Email.";
- $this->session->set_flashdata('message', $message);
- redirect('sales', 'refresh');
- }
- /*
- payment view
- */
- public function payment($id) {
- $data['data'] = $this->sales_model->getDetailsPayment($id);
- $data['company'] = $this->purchase_model->getCompany();
- $data['p_reference_no'] = $this->sales_model->generateReferenceNo();
- $this->load->view('sales/payment', $data);
- }
- /*
- get payment details to view and send to model
- */
- public function addPayment() {
- $id = $this->input->post('id');
- $paying_by = $this->input->post('paying_by');
- $this->form_validation->set_rules('date', 'Date', 'trim|required');
- $this->form_validation->set_rules('paying_by', 'Paying By', 'trim|required');
- if ($paying_by == "Cheque") {
- $this->form_validation->set_rules('bank_name', 'Bank Name', 'trim|required|callback_alpha_dash_space');
- $this->form_validation->set_rules('cheque_no', 'Cheque No', 'trim|required|numeric');
- }
- if ($this->form_validation->run() == false) {
- $this->payment($id);
- } else {
- if ($paying_by == "Cheque") {
- $bank_name = $this->input->post('bank_name');
- $cheque_no = $this->input->post('cheque_no');
- } else {
- $bank_name = "";
- $cheque_no = "";
- }
- $data = array(
- "sales_id" => $id,
- "date" => $this->input->post('date'),
- "reference_no" => $this->input->post('reference_no'),
- "amount" => $this->input->post('amount'),
- "paying_by" => $this->input->post('paying_by'),
- "bank_name" => $bank_name,
- "cheque_no" => $cheque_no,
- "description" => $this->input->post('note')
- );
- if ($this->sales_model->addPayment($data)) {
- $log_data = array(
- 'user_id' => $this->session->userdata('user_id'),
- 'table_id' => $id,
- 'message' => 'Sales Payable'
- );
- $this->log_model->insert_log($log_data);
- redirect('sales', 'refresh');
- } else {
- redirect("sales", 'refresh');
- }
- }
- }
- /*
- generate invoice
- */
- public function invoice() {
- $data['data'] = $this->sales_model->invoice();
- $this->load->view('invoice/list', $data);
- }
- /*
- */
- public function getCustomerData($id) {
- $data['data'] = $this->customer_model->getRecord($id);
- $data['country'] = $this->customer_model->getCountry();
- $data['state'] = $this->customer_model->getState($data['data'][0]->country_id);
- $data['city'] = $this->customer_model->getCity($data['data'][0]->state_id);
- $data['address'] = $this->customer_model->getListAddressRecord($id);
- echo json_encode($data);
- }
- public function getRecordAjax($id) {
- $data['data'] = $this->quotation_model->getRecordAjax($id);
- echo json_encode($data);
- }
- public function getCustomerAddressData($id) {
- $data['data'] = $this->customer_model->getRecord($id);
- $data['address'] = $this->customer_model->getCustomerAddressbyID($id);
- echo json_encode($data);
- }
- /*
- check character and space validation
- */
- function alpha_dash_space($str) {
- if (!preg_match("/^([a-zA-Z ])+$/i", $str)) {
- $this->form_validation->set_message('alpha_dash_space', 'The %s field may only contain alpha and spaces');
- return FALSE;
- } else {
- return TRUE;
- }
- }
- function currencyConverter2($currency_from, $currency_to) {
- if ($currency_from == $currency_to) {
- return 1;
- } else {
- //$currency_output = round(currency($currency_input, $currency_from,$currency_to, false),2);
- //$currency_input=substr($currency_input, 0, -3);
- $currency_input = filter_var(1, FILTER_SANITIZE_NUMBER_INT);
- $from_Currency = urlencode($currency_from);
- $to_Currency = urlencode($currency_to);
- $get = @file_get_contents("https://finance.google.com/finance/converter?a=1&from=$from_Currency&to=$to_Currency");
- $get = @explode("<span class=bld>", $get);
- $get = @explode("</span>", @$get[1]);
- $converted_currency = preg_replace("/[^0-9\.]/", null, @$get[0]);
- $converted_currency = $converted_currency;
- return $converted_currency;
- //return $currency_output;
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement