Example #1
0
 public function __construct()
 {
     parent::__construct();
     $this->purview_model->checkpurview(84);
     $this->load->model('data_model');
     $this->conf = $this->config->config;
     $this->name = str_no('jxc_') . '.sql';
     $this->load->helper(array('number', 'directory', 'download'));
 }
Example #2
0
 public function edit()
 {
     $this->purview_model->checkpurview(8);
     $id = intval($this->input->get('id', TRUE));
     $data = $this->input->post('postData', TRUE);
     if (strlen($data) > 0) {
         $data = (array) json_decode($data);
         !isset($data['id']) && die('{"status":-1,"msg":"参数错误"}');
         !isset($data['buId']) && $data['buId'] < 1 && die('{"status":-1,"msg":"请选择客户"}');
         $contact = $this->mysql_model->db_one(CONTACT, '(id=' . intval($data['buId']) . ')');
         count($contact) < 1 && die('{"status":-1,"msg":"请选择客户"}');
         $id = intval($data['id']);
         $info['billno'] = $data['billNo'];
         $info['type'] = intval($data['transType']);
         $info['contactid'] = $data['buId'];
         $info['contactname'] = $contact['number'] . ' ' . $contact['name'];
         $info['billdate'] = $data['date'];
         $info['disamount'] = $data['disAmount'];
         $info['disrate'] = $data['disRate'];
         $info['description'] = $data['description'];
         $info['totalamount'] = (double) $data['totalAmount'];
         $info['totalqty'] = (double) $data['totalQty'];
         $info['amount'] = $info['type'] == 1 ? $data['amount'] : -$data['amount'];
         //折扣后金额
         $info['rpamount'] = $info['type'] == 1 ? $data['rpAmount'] : -$data['rpAmount'];
         //已付款
         $info['arrears'] = $info['type'] == 1 ? $data['arrears'] : -$data['arrears'];
         //欠款
         $info['totalarrears'] = (double) $data['totalArrears'];
         $info['uid'] = $this->uid;
         $info['username'] = $this->name;
         $v = array();
         $this->db->trans_begin();
         $this->mysql_model->db_count(INVSA, '(id<>' . $id . ') and (billno="' . $info['billno'] . '")') > 0 && die('{"status":-1,"msg":"购货单已存在"}');
         $this->mysql_model->db_upd(INVSA, $info, '(id=' . $id . ')');
         $this->mysql_model->db_del(INVSA_INFO, '(invsaid=' . $id . ')');
         if (is_array($data['entries'])) {
             foreach ($data['entries'] as $arr => $row) {
                 $v[$arr]['invsaid'] = $id;
                 $v[$arr]['billno'] = $info['billno'];
                 $v[$arr]['contactid'] = $info['contactid'];
                 $v[$arr]['contactname'] = $info['contactname'];
                 $v[$arr]['type'] = $info['type'];
                 $v[$arr]['goodsid'] = $row->invId;
                 $v[$arr]['qty'] = $info['type'] == 1 ? $row->qty : -$row->qty;
                 $v[$arr]['amount'] = $info['type'] == 1 ? $row->amount : -$row->amount;
                 $v[$arr]['price'] = (double) $row->price;
                 $v[$arr]['discountrate'] = (double) $row->discountRate;
                 $v[$arr]['description'] = $row->description;
                 $v[$arr]['deduction'] = $row->deduction;
                 $v[$arr]['description'] = $row->description;
                 $v[$arr]['goodsno'] = $row->invNumber;
                 $v[$arr]['billdate'] = $data['date'];
             }
         }
         $this->mysql_model->db_inst(INVSA_INFO, $v);
         if ($this->db->trans_status() === FALSE) {
             $this->db->trans_rollback();
             die;
         } else {
             $this->db->trans_commit();
             $this->cache_model->delsome(GOODS);
             $this->cache_model->delsome(INVSA);
             $this->cache_model->delsome(INVSA_INFO);
             $this->data_model->logs('修改销货单 单据编号:' . $info['billno']);
             die('{"status":200,"msg":"success","data":{"id":' . $id . '}}');
         }
     } else {
         $data = $this->mysql_model->db_one(INVPU, '(id=' . $id . ')');
         if (count($data) > 0) {
             $this->load->view('invsa/edit', $data);
         } else {
             $data['billno'] = str_no('XS');
             $this->load->view('invsa/add', $data);
         }
     }
 }
Example #3
0
 public function generator()
 {
     $this->purview_model->checkpurview(12);
     $data = $this->input->post('postData', TRUE);
     if (strlen($data) > 0) {
         $i = 0;
         $n = 0;
         $a = 0;
         $b = 0;
         $qty1 = 0;
         $qty2 = 0;
         $amount1 = 0;
         $amount2 = 0;
         $msg = '';
         $v1 = array();
         $v2 = array();
         $data = (array) json_decode($data);
         $this->db->trans_begin();
         if (is_array($data['entries'])) {
             foreach ($data['entries'] as $arr => $row) {
                 if ($row->checkInventory < 0) {
                     die('{"status":400,"msg":"盘点库存要为数字,请输入有效数字!"}');
                 }
                 if ($row->change > 0) {
                     $i += 1;
                     $qty1 += (double) $row->change;
                     //总数量
                     $amount1 += $row->invCost * (double) $row->change;
                     //总价
                 } elseif ($row->change < 0) {
                     $n += 1;
                     $qty2 += abs($row->change);
                     $amount2 += $row->invCost * abs($row->change);
                 }
             }
         }
         if ($i == 0 && $n == 0) {
             die('{"status":400,"msg":"请先进行盘点!"}');
         }
         //盘盈
         if ($i > 0) {
             $info1['billno'] = str_no('QTRK');
             $info1['billdate'] = date('Y-m-d');
             $info1['type'] = 2;
             $info1['typename'] = '盘盈';
             $info1['description'] = $data['description'];
             $info1['totalamount'] = $amount1;
             $info1['totalqty'] = $qty1;
             $info1['username'] = $this->name;
             $info1['billtype'] = 1;
             $invoiid = $this->mysql_model->db_inst(INVOI, $info1);
             if (is_array($data['entries'])) {
                 foreach ($data['entries'] as $arr => $row) {
                     if ($row->change > 0) {
                         $v1[$a]['invoiid'] = $invoiid;
                         $v1[$a]['billno'] = $info1['billno'];
                         $v1[$a]['type'] = $info1['type'];
                         $v1[$a]['billtype'] = $info1['billtype'];
                         $v1[$a]['typename'] = $info1['typename'];
                         $v1[$a]['goodsid'] = $row->invId;
                         $v1[$a]['goodsno'] = $row->invNumber;
                         $v1[$a]['qty'] = abs($row->change);
                         $v1[$a]['amount'] = $row->invCost * abs($row->change);
                         $v1[$a]['price'] = $row->invCost;
                         $v1[$a]['billdate'] = $info1['billdate'];
                         $a += 1;
                     }
                 }
             }
             $this->mysql_model->db_inst(INVOI_INFO, $v1);
         }
         //盘亏
         if ($n > 0) {
             $info2['billno'] = str_no('QTCK');
             $info2['billdate'] = date('Y-m-d');
             $info2['type'] = 4;
             $info2['typename'] = '盘亏';
             $info2['description'] = $data['description'];
             $info2['totalamount'] = $amount2;
             $info2['totalqty'] = $qty2;
             $info2['username'] = $this->name;
             $info2['billtype'] = 2;
             $invoiid = $this->mysql_model->db_inst(INVOI, $info2);
             if (is_array($data['entries'])) {
                 foreach ($data['entries'] as $arr => $row) {
                     if ($row->change >= 0) {
                     } else {
                         $v2[$b]['invoiid'] = $invoiid;
                         $v2[$b]['billno'] = $info2['billno'];
                         $v2[$b]['type'] = $info2['type'];
                         $v2[$b]['billtype'] = $info2['billtype'];
                         $v2[$b]['typename'] = $info2['typename'];
                         $v2[$b]['goodsid'] = $row->invId;
                         $v2[$b]['goodsno'] = $row->invNumber;
                         $v2[$b]['qty'] = $row->change;
                         $v2[$b]['amount'] = $row->invCost * abs($row->change);
                         $v2[$b]['price'] = $row->invCost;
                         $v2[$b]['billdate'] = $info2['billdate'];
                         $b += 1;
                     }
                 }
             }
             $this->mysql_model->db_inst(INVOI_INFO, $v2);
         }
         if ($this->db->trans_status() === FALSE) {
             $this->db->trans_rollback();
             die('{"status":400,"msg":"盘点失败!"}');
         } else {
             $this->db->trans_commit();
             $this->cache_model->delsome(GOODS);
             $this->cache_model->delsome(INVOI);
             $this->cache_model->delsome(INVOI_INFO);
             if ($i > 0) {
                 $msg .= '成功生成其他入库单 单据编号为' . $info1['billno'] . ' ';
             }
             if ($n > 0) {
                 $msg .= '其他出库单 单据编号为' . $info2['billno'] . '';
             }
             $this->data_model->logs('生成盘点记录');
             die('{"status":200,"msg":"' . $msg . '"}');
         }
     }
     die('{"status":400,"msg":"请先进行盘点!"}');
 }