芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/www/breadwinnerv2/application/controllers/Purchase.php
load->model('purchase_model', 'purchase'); $this->load->library("Aauth"); if (!$this->aauth->is_loggedin()) { redirect('/user/', 'refresh'); } if ($this->aauth->get_user()->roleid < 3) { exit('
Sorry! You have insufficient permissions to access this section
'); } } //create invoice public function create() { $this->load->model('customers_model', 'customers'); $data['customergrouplist'] = $this->customers->group_list(); $data['lastinvoice'] = $this->purchase->lastpurchase(); $data['terms'] = $this->purchase->billingterms(); $head['title'] = "New Purchase"; $head['usernm'] = $this->aauth->get_user()->username; $data['warehouse'] = $this->purchase->warehouses(); $this->load->view('fixed/header', $head); $this->load->view('purchase/newinvoice', $data); $this->load->view('fixed/footer'); } //edit invoice public function edit() { $tid = intval($this->input->get('id')); $data['id'] = $tid; $data['title'] = "Purchase Order $tid"; $this->load->model('customers_model', 'customers'); $data['customergrouplist'] = $this->customers->group_list(); $data['terms'] = $this->purchase->billingterms(); $data['invoice'] = $this->purchase->purchase_details($tid); $data['products'] = $this->purchase->purchase_products($tid);; $head['title'] = "Edit Invoice #$tid"; $head['usernm'] = $this->aauth->get_user()->username; $data['warehouse'] = $this->purchase->warehouses(); $this->load->view('fixed/header', $head); $this->load->view('purchase/edit', $data); $this->load->view('fixed/footer'); } //invoices list public function index() { $head['title'] = "Manage Purchase Orders"; $head['usernm'] = $this->aauth->get_user()->username; $this->load->view('fixed/header', $head); $this->load->view('purchase/invoices'); $this->load->view('fixed/footer'); } //action public function action() { $customer_id = $this->input->post('customer_id'); $invocieno = $this->input->post('invocieno'); $invoicedate = $this->input->post('invoicedate'); $invocieduedate = $this->input->post('invocieduedate'); $notes = $this->input->post('notes',true); $tax = $this->input->post('tax_handle'); $subtotal = $this->input->post('subtotal'); $shipping = $this->input->post('shipping'); $refer = $this->input->post('refer'); $total = $this->input->post('total'); $total_tax = 0; $total_discount = 0; $discountFormat = $this->input->post('discountFormat'); $pterms = $this->input->post('pterms'); $i = 0; if ($discountFormat == '0') { $discstatus = 0; } else { $discstatus = 1; } if ($customer_id == 0) { echo json_encode(array('status' => 'Error', 'message' => "Please add a new supplier or search from a previous added!")); exit; } $this->db->trans_start(); //products $pid = $this->input->post('pid'); $productlist = array(); $prodindex = 0; $itc = 0; $flag = false; if ($tax == 'yes') { $textst = 1; foreach ($pid as $key => $value) { $product_id = $this->input->post('pid'); $product_name1 = $this->input->post('product_name',true); $product_qty = $this->input->post('product_qty'); $product_price = $this->input->post('product_price'); $product_tax = $this->input->post('product_tax'); $product_discount = $this->input->post('product_discount'); $product_subtotal = $this->input->post('product_subtotal'); $ptotal_tax = $this->input->post('taxa'); $ptotal_disc = $this->input->post('disca'); $total_discount += $ptotal_disc[$key]; $total_tax += $ptotal_tax[$key]; $product_des = $this->input->post('product_description',true); $data = array( 'tid' => $invocieno, 'pid' => $product_id[$key], 'product' => $product_name1[$key], 'qty' => $product_qty[$key], 'price' => $product_price[$key], 'tax' => $product_tax[$key], 'discount' => $product_discount[$key], 'subtotal' => $product_subtotal[$key], 'totaltax' => $ptotal_tax[$key], 'totaldiscount' => $ptotal_disc[$key], 'product_des' => $product_des[$key] ); $flag = true; $productlist[$prodindex] = $data; $i++; $prodindex++; $amt = intval($product_qty[$key]); if ($product_id[$key] > 0) { if ($this->input->post('update_stock') == 'yes') { $this->db->set('qty', "qty+$amt", FALSE); $this->db->where('pid', $product_id[$key]); $this->db->update('products'); } $itc += $amt; } } } else { $textst = 0; foreach ($pid as $key => $value) { $product_id = $this->input->post('pid'); $product_name1 = $this->input->post('product_name',true); $product_qty = $this->input->post('product_qty'); $product_price = $this->input->post('product_price'); $product_discount = $this->input->post('product_discount'); $product_subtotal = $this->input->post('product_subtotal'); $ptotal_disc = $this->input->post('disca'); $product_des = $this->input->post('product_description',true); $data = array( 'tid' => $invocieno, 'pid' => $product_id[$key], 'product' => $product_name1[$key], 'qty' => $product_qty[$key], 'price' => $product_price[$key], 'discount' => $product_discount[$key], 'subtotal' => $product_subtotal[$key], 'totaldiscount' => $ptotal_disc[$key], 'product_des' => $product_des[$key] ); $flag = true; $productlist[$prodindex] = $data; $i++; $prodindex++; $amt = intval($product_qty[$key]); if ($product_id[$key] > 0) { if ($this->input->post('update_stock') == 'yes') { $this->db->set('qty', "qty+$amt", FALSE); $this->db->where('pid', $product_id[$key]); $this->db->update('products'); } } $itc += $amt; } } $transok = true; //Invoice Data $bill_date = datefordatabase($invoicedate); $bill_due_date = datefordatabase($invocieduedate); $data = array('tid' => $invocieno, 'invoicedate' => $bill_date, 'invoiceduedate' => $bill_due_date, 'subtotal' => $subtotal, 'shipping' => $shipping, 'discount' => $total_discount, 'tax' => $total_tax, 'total' => $total, 'notes' => $notes, 'csd' => $customer_id, 'eid' => $this->aauth->get_user()->id, 'items' => $itc, 'taxstatus' => $textst, 'discstatus' => $discstatus, 'format_discount' => $discountFormat, 'refer' => $refer, 'term' => $pterms); if ($flag == true) { $this->db->insert_batch('purchase_items', $productlist); if ($this->db->insert('purchase', $data)) { echo json_encode(array('status' => 'Success', 'message' => $this->lang->line('Purchase order success')."
".$this->lang->line('View')."
")); } else { echo json_encode(array('status' => 'Error', 'message' => $this->lang->line('ERROR'))); $transok = false; } } else { echo json_encode(array('status' => 'Error', 'message' => "Please choose product from product list. Go to Item manager section if you have not added the products.")); $transok = false; } if ($transok) { $this->db->trans_complete(); } else { $this->db->trans_rollback(); } } public function ajax_list() { $list = $this->purchase->get_datatables(); $data = array(); $no = $this->input->post('start'); foreach ($list as $invoices) { $no++; $row = array(); $row[] = $no; $row[] = $invoices->tid; $row[] = $invoices->name; $row[] = dateformat($invoices->invoicedate); $row[] = amountFormat($invoices->total); $row[] = '
' . $this->lang->line(ucwords($invoices->status)) . '
'; $row[] = '
tid") . '" class="btn btn-success btn-xs">
' . $this->lang->line('View') . '
tid") . '&d=1" class="btn btn-info btn-xs" title="Download">
'; $data[] = $row; } $output = array( "draw" => $_POST['draw'], "recordsTotal" => $this->purchase->count_all(), "recordsFiltered" => $this->purchase->count_filtered(), "data" => $data, ); //output to json format echo json_encode($output); } public function view() { $this->load->model('accounts_model'); $data['acclist'] = $this->accounts_model->accountslist(); $tid = intval($this->input->get('id')); $data['id'] = $tid; $head['title'] = "Purchase $tid"; $data['invoice'] = $this->purchase->purchase_details($tid); $data['products'] = $this->purchase->purchase_products($tid); $data['activity'] = $this->purchase->purchase_transactions($tid); $data['attach'] = $this->purchase->attach($tid); $data['employee'] = $this->purchase->employee($data['invoice']['eid']); $head['usernm'] = $this->aauth->get_user()->username; $this->load->view('fixed/header', $head); $this->load->view('purchase/view', $data); $this->load->view('fixed/footer'); } public function printinvoice() { $tid = $this->input->get('id'); $data['id'] = $tid; $data['title'] = "Purchase $tid"; $data['invoice'] = $this->purchase->purchase_details($tid); $data['products'] = $this->purchase->purchase_products($tid); $data['employee'] = $this->purchase->employee($data['invoice']['eid']); $data['invoice']['multi'] = 0; ini_set('memory_limit', '-1'); $html = $this->load->view('purchase/view-print-'.LTR, $data, true); //PDF Rendering $this->load->library('pdf'); $pdf = $this->pdf->load(); $pdf->SetHTMLFooter('
{DATE j-m-Y}
{PAGENO}/{nbpg}
#' . $tid . '
'); $pdf->WriteHTML($html); if ($this->input->get('d')) { $pdf->Output('Purchase_#' . $tid . '.pdf', 'D'); } else { $pdf->Output('Purchase_#' . $tid . '.pdf', 'I'); } } public function delete_i() { $id = $this->input->post('deleteid'); if ($this->purchase->purchase_delete($id)) { echo json_encode(array('status' => 'Success', 'message' => "Purchase Order #$id has been deleted successfully!")); } else { echo json_encode(array('status' => 'Error', 'message' => "There is an error! Purchase has not deleted.")); } } public function editaction() { $customer_id = $this->input->post('customer_id'); $invocieno = $this->input->post('invocieno'); $invoicedate = $this->input->post('invoicedate'); $invocieduedate = $this->input->post('invocieduedate'); $notes = $this->input->post('notes',true); $tax = $this->input->post('tax_handle'); $subtotal = $this->input->post('subtotal'); $shipping = $this->input->post('shipping'); $refer = $this->input->post('refer',true); $total = $this->input->post('total'); $total_tax = 0; $total_discount = 0; $discountFormat = $this->input->post('discountFormat'); $pterms = $this->input->post('pterms'); $i = 0; if ($discountFormat == '0') { $discstatus = 0; } else { $discstatus = 1; } if ($customer_id == 0) { echo json_encode(array('status' => 'Error', 'message' => "Please add a new supplier or search from a previous added!")); exit; } $this->db->trans_start(); $flag = false; $transok = true; //Product Data $pid = $this->input->post('pid'); $productlist = array(); $prodindex = 0; $this->db->delete('purchase_items', array('tid' => $invocieno)); if ($tax == 'yes') { $taxstatus = 1; foreach ($pid as $key => $value) { $product_id = $this->input->post('pid'); $product_name1 = $this->input->post('product_name',true); $product_qty = $this->input->post('product_qty'); $old_product_qty = $this->input->post('old_product_qty'); if ($old_product_qty == '') $old_product_qty = 0; $product_price = $this->input->post('product_price'); $product_tax = $this->input->post('product_tax'); $product_discount = $this->input->post('product_discount'); $product_subtotal = $this->input->post('product_subtotal'); $ptotal_tax = $this->input->post('taxa'); $ptotal_disc = $this->input->post('disca'); $total_discount += $ptotal_disc[$key]; $total_tax += $ptotal_tax[$key]; $product_des = $this->input->post('product_description',true); $data = array( 'tid' => $invocieno, 'pid' => $product_id[$key], 'product' => $product_name1[$key], 'qty' => $product_qty[$key], 'price' => $product_price[$key], 'tax' => $product_tax[$key], 'discount' => $product_discount[$key], 'subtotal' => $product_subtotal[$key], 'totaltax' => $ptotal_tax[$key], 'totaldiscount' => $ptotal_disc[$key], 'product_des' => $product_des[$key] ); $productlist[$prodindex] = $data; $i++; $prodindex++; if ($this->input->post('update_stock') == 'yes') { $amt = intval($product_qty[$key]) - @intval($old_product_qty[$key]); $this->db->set('qty', "qty+$amt", FALSE); $this->db->where('pid', $product_id[$key]); $this->db->update('products'); } $flag = true; } } else { $taxstatus = 0; foreach ($pid as $key => $value) { $product_id = $this->input->post('pid'); $product_name1 = $this->input->post('product_name',true); $product_qty = $this->input->post('product_qty'); $old_product_qty = $this->input->post('old_product_qty'); if ($old_product_qty == '') $old_product_qty = 0; $product_price = $this->input->post('product_price'); $product_discount = $this->input->post('product_discount'); $product_subtotal = $this->input->post('product_subtotal'); $product_des = $this->input->post('product_description',true); $ptotal_disc = $this->input->post('disca'); $total_discount += $ptotal_disc[$key]; $data = array( 'tid' => $invocieno, 'product' => $product_name1, 'qty' => $product_qty, 'price' => $product_price, 'discount' => $product_discount, 'subtotal' => $product_subtotal, 'product_des' => $product_des[$key] ); $productlist[$prodindex] = $data; $i++; $prodindex++; if ($this->input->post('update_stock') == 'yes') { $amt = intval($product_qty[$key]) - intval($old_product_qty[$key]); $this->db->set('qty', "qty+$amt", FALSE); $this->db->where('pid', $product_id[$key]); $this->db->update('products'); } $flag = true; } } $bill_date = datefordatabase($invoicedate); $bill_due_date = datefordatabase($invocieduedate); $data = array('invoicedate' => $bill_date, 'invoiceduedate' => $bill_due_date, 'subtotal' => $subtotal, 'shipping' => $shipping, 'discount' => $total_discount, 'tax' => $total_tax, 'total' => $total, 'notes' => $notes, 'csd' => $customer_id, 'items' => $i, 'taxstatus' => $taxstatus, 'discstatus' => $discstatus, 'format_discount' => $discountFormat, 'refer' => $refer, 'term' => $pterms); $this->db->set($data); $this->db->where('tid', $invocieno); if ($flag) { if ($this->db->update('purchase', $data)) { $this->db->insert_batch('purchase_items', $productlist); echo json_encode(array('status' => 'Success', 'message' => "Purchase order has been updated successfully!
View
")); } else { echo json_encode(array('status' => 'Error', 'message' => "There is a missing field!")); $transok = false; } } else { echo json_encode(array('status' => 'Error', 'message' => "Please add atleast one product in order!")); $transok = false; } if ($this->input->post('update_stock') == 'yes') { if ($this->input->post('restock')) { foreach ($this->input->post('restock') as $key => $value) { $myArray = explode('-', $value); $prid = $myArray[0]; $dqty = $myArray[1]; if ($prid > 0) { $this->db->set('qty', "qty-$dqty", FALSE); $this->db->where('pid', $prid); $this->db->update('products'); } } } } if ($transok) { $this->db->trans_complete(); } else { $this->db->trans_rollback(); } } public function update_status() { $tid = $this->input->post('tid'); $status = $this->input->post('status'); $this->db->set('status', $status); $this->db->where('tid', $tid); $this->db->update('purchase'); echo json_encode(array('status' => 'Success', 'message' => 'Purchase Order Status updated successfully!', 'pstatus' => $status)); } public function file_handling() { if($this->input->get('op')) { $name = $this->input->get('name'); $invoice = $this->input->get('invoice'); if ($this->purchase->meta_delete($invoice,4, $name)){ echo json_encode(array('status' => 'Success')); } } else { $id = $this->input->get('id'); $this->load->library("Uploadhandler_generic", array( 'accept_file_types' => '/\.(gif|jpe?g|png|docx|docs|txt|pdf|xls)$/i', 'upload_dir' => FCPATH . 'userfiles/attach/', 'upload_url' => base_url() . 'userfiles/attach/' )); $files = (string)$this->uploadhandler_generic->filenaam(); if ($files != '') { $this->purchase->meta_insert($id, 4, $files); } } } }