public function getData($condition, $receive_id = null, $type = '采购收货') { $sql = $this->select()->setIntegrityCheck(false)->from(array('t1' => $this->_name))->joinLeft(array('t2' => $this->_dbprefix . 'user'), "t1.create_user = t2.id", array())->joinLeft(array('t3' => $this->_dbprefix . 'employee'), "t2.employee_id = t3.id", array('creater' => 'cname'))->joinLeft(array('t4' => $this->_dbprefix . 'user'), "t1.update_user = t4.id", array())->joinLeft(array('t5' => $this->_dbprefix . 'employee'), "t4.employee_id = t5.id", array('updater' => 'cname'))->where("t1.type = '" . $type . "'"); if ($receive_id) { $sql->where("t1.id = " . $receive_id); return $this->fetchRow($sql)->toArray(); } else { if ($condition['date_from']) { $sql->where("t1.create_time >= '" . $condition['date_from'] . " 00:00:00'"); } if ($condition['date_to']) { $sql->where("t1.create_time <= '" . $condition['date_to'] . " 23:59:59'"); } if ($condition['key']) { $sql->where("t1.number like '%" . $condition['key'] . "%' \n or t1.description like '%" . $condition['key'] . "%' \n or t1.remark like '%" . $condition['key'] . "%'"); // or t8.name like '%".$condition['key']."%' } $total = $this->fetchAll($sql)->count(); $sql->order(array('t1.number desc', 't1.create_time desc')); if ($condition['type'] != 'csv') { $sql->limitPage($condition['page'], $condition['limit']); } $data = $this->fetchAll($sql)->toArray(); $receive_items = new Erp_Model_Purchse_Receiveitems(); for ($i = 0; $i < count($data); $i++) { $data[$i]['create_time'] = strtotime($data[$i]['create_time']); $data[$i]['update_time'] = strtotime($data[$i]['update_time']); $orderInfo = $receive_items->getOrderNumbersByReceiveId($data[$i]['id'], $type); $data[$i]['order_number'] = implode(',', $orderInfo['order_number']); if ($type == '采购收货') { $suppliers = array(); foreach ($orderInfo['supplier'] as $s) { if (!in_array($s, $suppliers)) { array_push($suppliers, $s); } } $data[$i]['supplier'] = implode(',', $suppliers); } else { $customers = array(); foreach ($orderInfo['customer'] as $c) { if (!in_array($c, $customers)) { array_push($customers, $c); } } $data[$i]['customer'] = implode(',', $customers); } } if ($condition['type'] == 'csv') { $data_csv = array(); $showAmount = false; if (Application_Model_User::checkPermissionByRoleName('系统管理员') || Application_Model_User::checkPermissionByRoleName('财务人员') || ($type = '采购收货' || ($type = '采购退货' || ($type = '调拨'))) && Application_Model_User::checkPermissionByRoleName('采购人员') || ($type = '销售交货' && Application_Model_User::checkPermissionByRoleName('销售人员'))) { $showAmount = true; } if ($showAmount) { if (isset($condition['action_type']) && $condition['action_type'] == '采购收货') { $title = array('cnt' => '#', 'number' => '收货单号', 'order_number' => '采购订单', 'total' => '金额', 'supplier' => '供应商', 'date' => '收货日期', 'description' => '描述', 'remark' => '备注', 'creater' => '收货人', 'create_time' => '收货时间'); } else { if (isset($condition['action_type']) && $condition['action_type'] == '销售交货') { $title = array('cnt' => '#', 'number' => '交货单号', 'order_number' => '销售订单', 'total' => '金额', 'customer' => '客户', 'date' => '交货日期', 'description' => '描述', 'remark' => '备注', 'creater' => '交货人', 'create_time' => '交货时间'); } else { $title = array('cnt' => '#', 'transaction_type' => '库存交易类别', 'number' => '单据号', 'date' => '单据日期', 'total' => '金额', 'description' => '描述', 'remark' => '备注', 'creater' => '制单人', 'create_time' => '制单时间'); } } } else { if (isset($condition['action_type']) && $condition['action_type'] == '采购收货') { $title = array('cnt' => '#', 'number' => '收货单号', 'order_number' => '采购订单', 'supplier' => '供应商', 'date' => '收货日期', 'description' => '描述', 'remark' => '备注', 'creater' => '收货人', 'create_time' => '收货时间'); } else { if (isset($condition['action_type']) && $condition['action_type'] == '销售交货') { $title = array('cnt' => '#', 'number' => '交货单号', 'order_number' => '销售订单', 'customer' => '客户', 'date' => '交货日期', 'description' => '描述', 'remark' => '备注', 'creater' => '交货人', 'create_time' => '交货时间'); } else { $title = array('cnt' => '#', 'transaction_type' => '库存交易类别', 'number' => '单据号', 'date' => '单据日期', 'description' => '描述', 'remark' => '备注', 'creater' => '制单人', 'create_time' => '制单时间'); } } } array_push($data_csv, $title); $i = 0; foreach ($data as $d) { $i++; if ($showAmount) { if (isset($condition['action_type']) && $condition['action_type'] == '采购收货') { $info = array('cnt' => $i, 'number' => $d['number'], 'order_number' => $d['order_number'], 'total' => $d['total'], 'supplier' => $d['supplier'], 'date' => $d['date'], 'description' => $d['description'], 'remark' => $d['remark'], 'creater' => $d['creater'], 'create_time' => date('Y-m-d H:i:s', $d['create_time'])); } else { if (isset($condition['action_type']) && $condition['action_type'] == '销售交货') { $info = array('cnt' => $i, 'number' => $d['number'], 'order_number' => $d['order_number'], 'total' => $d['total'], 'customer' => $d['customer'], 'date' => $d['date'], 'description' => $d['description'], 'remark' => $d['remark'], 'creater' => $d['creater'], 'create_time' => date('Y-m-d H:i:s', $d['create_time'])); } else { $info = array('cnt' => $i, 'transaction_type' => $d['transaction_type'], 'number' => $d['number'], 'date' => $d['date'], 'total' => $d['total'], 'description' => $d['description'], 'remark' => $d['remark'], 'creater' => $d['creater'], 'create_time' => date('Y-m-d H:i:s', $d['create_time'])); } } } else { if (isset($condition['action_type']) && $condition['action_type'] == '采购收货') { $info = array('cnt' => $i, 'number' => $d['number'], 'order_number' => $d['order_number'], 'supplier' => $d['supplier'], 'date' => $d['date'], 'description' => $d['description'], 'remark' => $d['remark'], 'creater' => $d['creater'], 'create_time' => date('Y-m-d H:i:s', $d['create_time'])); } else { if (isset($condition['action_type']) && $condition['action_type'] == '销售交货') { $info = array('cnt' => $i, 'number' => $d['number'], 'order_number' => $d['order_number'], 'customer' => $d['customer'], 'date' => $d['date'], 'description' => $d['description'], 'remark' => $d['remark'], 'creater' => $d['creater'], 'create_time' => date('Y-m-d H:i:s', $d['create_time'])); } else { $info = array('cnt' => $i, 'transaction_type' => $d['transaction_type'], 'number' => $d['number'], 'date' => $d['date'], 'description' => $d['description'], 'remark' => $d['remark'], 'creater' => $d['creater'], 'create_time' => date('Y-m-d H:i:s', $d['create_time'])); } } } array_push($data_csv, $info); } return $data_csv; } return array('total' => $total, 'rows' => $data); } }
public function edititemsAction() { // 返回值数组 $result = array('success' => true, 'info' => '编辑成功'); $request = $this->getRequest()->getParams(); $now = date('Y-m-d H:i:s'); $user_session = new Zend_Session_Namespace('user'); $user_id = $user_session->user_info['user_id']; $json = json_decode($request['json']); $return_id = $json->return_id; $json_items = $json->items; $items_updated = $json_items->updated; $items_inserted = $json_items->inserted; $items_deleted = $json_items->deleted; $receive = new Erp_Model_Stock_receive(); $items = new Erp_Model_Purchse_Receiveitems(); $itemsorder = new Erp_Model_Purchse_Receiveitemsorder(); $receiveData = $receive->getData(null, $return_id, '采购退货'); // 更新 if (count($items_updated) > 0) { foreach ($items_updated as $val) { $data = array('order_number' => $val->items_order_number, 'code' => $val->items_code, 'name' => $val->items_name, 'description' => $val->items_description, 'qty' => $val->items_qty, 'unit' => $val->items_unit, 'remark' => $val->items_remark, 'update_user' => $user_id, 'update_time' => $now); try { $items->update($data, "id = " . $val->items_id); // 记录分拆数据 $splitData = array('receive_number' => $receiveData['number'], 'receive_item_id' => $val->items_id, 'items_order_qty' => $val->items_order_qty, 'items_order_item_price' => $val->items_order_item_price, 'items_code' => $val->items_code, 'items_order_id' => $val->items_order_id, 'items_order_number' => $val->items_order_number); $this->saveSplitItem($splitData); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } } // 此次退货货的采购订单号 $orderNumArr = array(); // 插入 if (count($items_inserted) > 0) { foreach ($items_inserted as $val) { $data = array('receive_id' => $return_id, 'order_number' => $val->items_order_number, 'code' => $val->items_code, 'name' => $val->items_name, 'description' => $val->items_description, 'qty' => $val->items_qty, 'price' => $val->items_price, 'unit' => $val->items_unit, 'remark' => $val->items_remark, 'warehouse_code' => $val->items_warehouse_code, 'create_user' => $user_id, 'create_time' => $now, 'update_user' => $user_id, 'update_time' => $now); try { $receive_item_id = $items->insert($data); // 记录分拆数据 $splitData = array('return_number' => $receiveData['number'], 'receive_item_id' => $receive_item_id, 'items_qty' => $val->items_qty, 'items_price' => $val->items_price, 'items_code' => $val->items_code, 'items_order_id' => $val->items_order_id, 'items_order_item_id' => $val->items_order_item_id, 'items_warehouse_code' => $val->items_warehouse_code, 'items_order_number' => $val->items_order_number); $this->saveSplitItem($splitData); if (!in_array($val->items_order_number, $orderNumArr)) { array_push($orderNumArr, $val->items_order_number); } } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } } // 更新总计 $items->refreshReceiveTotal($return_id); // 退货通知 $receive_items_order = new Erp_Model_Purchse_Receiveitemsorder(); $order = new Erp_Model_Purchse_Order(); $relatedUserInfo = count($orderNumArr) > 0 ? $receive_items_order->getReqRelatedUsers($orderNumArr) : array(); $member = new Admin_Model_Member(); $warehouse = new Erp_Model_Warehouse_Warehouse(); $noticeTo = $member->getMemberWithManagerByName('采购退货通知'); $noticeMails = array(); $noticeUsers = array(); foreach ($noticeTo as $n) { if ($n['email'] != '' && !in_array($n['user_id'], $noticeUsers)) { array_push($noticeMails, $n['email']); array_push($noticeUsers, $n['user_id']); } } foreach ($relatedUserInfo as $n) { if ($n['email'] != '' && !in_array($n['user_id'], $noticeUsers)) { array_push($noticeMails, $n['email']); array_push($noticeUsers, $n['user_id']); } } $mail = new Application_Model_Log_Mail(); $supplierArr = array(); $i = 0; $itemsTable = '<style type="text/css"> table.gridtable { font-family: verdana,arial,sans-serif; font-size:11px; color:#333333; border-width: 1px; border-color: #666666; border-collapse: collapse; } table.gridtable th { border-width: 1px; padding: 8px; border-style: solid; border-color: #666666; background-color: #dedede; } table.gridtable td { border-width: 1px; padding: 8px; border-style: solid; border-color: #666666; background-color: #ffffff; } </style><table class="gridtable"><tr> <th>#</th> <th>供应商</th> <th>采购订单</th> <th>物料号</th> <th>物料名称</th> <th>物料描述</th> <th>退货数量</th> <th>单位</th> <th>退货仓库</th> <th>备注</th> <th>订单信息</th> </tr>'; foreach ($items_inserted as $val) { $itemInfo = ''; if ($val->items_order_number) { $itemInfoData = $order->getItemDetails($val->items_order_number, $val->items_code); $itemInfo = '<table class="gridtable"><tr> <th>申请单号</th> <th>申请日期</th> <th>申请数量</th> <th>下单数量</th> <th>订单数量</th> <th>客户收件人地址简码</th> <th>客户合同号</th> </tr>'; foreach ($itemInfoData as $d) { $itemInfo .= '<tr> <td>' . $d['req_number'] . '</td> <td>' . $d['req_item_date'] . '</td> <td>' . $d['req_item_qty'] . '</td> <td>' . $d['order_req_item_qty'] . '</td> <td>' . $d['order_item_qty'] . '</td> <td>' . $d['customer_address'] . '</td> <td>' . $d['customer_aggrement'] . '</td> </tr>'; } $itemInfo .= '</table>'; $supplier = $d['supplier_code'] . ' ' . $d['supplier_name']; if (!in_array($supplier, $supplierArr)) { array_push($supplierArr, $supplier); } } $i++; $warehouseInfo = $warehouse->getInfoByCode($val->items_warehouse_code); $itemsTable .= '<tr> <td>' . $i . '</td> <td>' . $supplier . '</td> <td>' . $val->items_order_number . '</td> <td>' . $val->items_code . '</td> <td>' . $val->items_name . '</td> <td>' . $val->items_description . '</td> <td>' . $val->items_qty . '</td> <td>' . $val->items_unit . '</td> <td>' . $val->items_warehouse_code . ' ' . $warehouseInfo['name'] . '</td> <td>' . $val->items_remark . '</td> <td>' . $itemInfo . '</td> </tr>'; } $itemsTable .= '</table>'; $mailContent = '<div>采购退货,请登录系统查看:</div> <div> <p><b>退货单号:</b>' . $receiveData['number'] . '</p> <p><b>收货日期:</b>' . $receiveData['date'] . '</p> <p><b>收货人:</b>' . $user_session->user_info['user_name'] . '</p> <p><b>描述:</b>' . $receiveData['description'] . '</p> <p><b>备注:</b>' . $receiveData['remark'] . '</p> </div><div>' . $itemsTable . '</div><hr>'; $mailData = array('type' => '通知', 'subject' => '退货通知 - ' . $receiveData['number'] . ' - ' . implode(', ', $supplierArr), 'cc' => $user_session->user_info['user_email'], 'content' => $mailContent, 'add_date' => $now, 'to' => implode(',', $noticeMails), 'user_id' => implode(',', $noticeUsers)); try { // 记录邮件日志并发送邮件 $mail->send($mail->insert($mailData)); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); } echo Zend_Json::encode($result); exit; }
function cancelOrder($id) { $result = array('success' => true, 'info' => '取消成功'); $order = new Erp_Model_Purchse_Order(); $orderData = $order->getData(null, $id); // 取消订单:如当前订单状态为被拒绝,则直接取消,否则检查是否存在收货订单项 if ($orderData['state'] == 1) { $order->cancelOrderById($id); } else { $receiveItems = new Erp_Model_Purchse_Receiveitems(); $items = $receiveItems->getReceivedOrderItems($orderData['number']); if (count($items)) { $codeArr = array(); foreach ($items as $item) { array_push($codeArr, $item['code']); } $result['success'] = false; $result['info'] = '取消失败,[' . implode(',', $codeArr) . '] 已收货!'; } else { $order->cancelOrderById($id); } } return $result; }
public function mailByHand($receive_id) { // 返回值数组 $result = array('success' => true, 'info' => '编辑成功'); $now = date('Y-m-d H:i:s'); $user_session = new Zend_Session_Namespace('user'); $user_id = $user_session->user_info['user_id']; $receive = new Erp_Model_Stock_receive(); $items = new Erp_Model_Purchse_Receiveitems(); $itemsorder = new Erp_Model_Purchse_Receiveitemsorder(); $receive_items_order = new Erp_Model_Purchse_Receiveitemsorder(); $order = new Erp_Model_Purchse_Order(); $receiveData = $receive->getData(null, $receive_id); $itemsData = $items->getData($receive_id); $orderNumArr = array(); foreach ($itemsData as $item) { $numbers = explode(',', $item['items_order_number']); foreach ($numbers as $number) { if (!in_array($number, $orderNumArr)) { array_push($orderNumArr, $number); } } } // 订单关联人员(申请人、审核人) $relatedUserInfo = count($orderNumArr) > 0 ? $receive_items_order->getReqRelatedUsers($orderNumArr) : array(); // 到货通知 $member = new Admin_Model_Member(); $warehouse = new Erp_Model_Warehouse_Warehouse(); $noticeTo = $member->getMemberWithManagerByName('采购到货通知'); $noticeMails = array(); $noticeUsers = array(); foreach ($noticeTo as $n) { if ($n['email'] != '' && !in_array($n['user_id'], $noticeUsers)) { array_push($noticeMails, $n['email']); array_push($noticeUsers, $n['user_id']); } } foreach ($relatedUserInfo as $n) { if ($n['email'] != '' && !in_array($n['user_id'], $noticeUsers)) { array_push($noticeMails, $n['email']); array_push($noticeUsers, $n['user_id']); } } $mail = new Application_Model_Log_Mail(); $supplierArr = array(); $supplierIdArr = array(); $i = 0; $itemsTable = '<style type="text/css"> table.gridtable { font-family: verdana,arial,sans-serif; font-size:11px; color:#333333; border-width: 1px; border-color: #666666; border-collapse: collapse; } table.gridtable th { border-width: 1px; padding: 8px; border-style: solid; border-color: #666666; background-color: #dedede; } table.gridtable td { border-width: 1px; padding: 8px; border-style: solid; border-color: #666666; background-color: #ffffff; } </style><table class="gridtable"><tr> <th>#</th> <th>供应商</th> <th>采购订单</th> <th>物料号</th> <th>物料名称</th> <th>物料描述</th> <th>收货数量</th> <th>单位</th> <th>收货仓库</th> <th>备注</th> <th>备注</th> <th>申请信息</th> </tr>'; foreach ($itemsData as $val) { $itemInfo = ''; if ($val['items_order_number']) { $itemInfoData = $order->getItemDetails($val['items_order_number'], $val['items_code']); $itemInfo = '<table class="gridtable"><tr> <th>申请单号</th> <th>申请日期</th> <th>申请数量</th> <th>下单数量</th> <th>订单数量</th> <th>客户收件人地址简码</th> <th>客户合同号</th> </tr>'; foreach ($itemInfoData as $d) { $itemInfo .= '<tr> <td>' . $d['req_number'] . '</td> <td>' . $d['req_item_date'] . '</td> <td>' . $d['req_item_qty'] . '</td> <td>' . $d['order_req_item_qty'] . '</td> <td>' . $d['order_item_qty'] . '</td> <td>' . $d['customer_address'] . '</td> <td>' . $d['customer_aggrement'] . '</td> </tr>'; } $itemInfo .= '</table>'; } $i++; $numberArr = explode(',', $val['items_order_number']); foreach ($numberArr as $n) { $supplierData = $order->getSupplierByNumber($n); if (isset($supplierData['id']) && !in_array($supplierData['id'], $supplierIdArr)) { array_push($supplierArr, $supplierData['supplier_code'] . ' ' . $supplierData['supplier_name']); array_push($supplierIdArr, $supplierData['id']); } } $warehouseInfo = $warehouse->getInfoByCode($val['items_warehouse_code']); $itemsTable .= '<tr> <td>' . $i . '</td> <td>' . implode(', ', $supplierArr) . '</td> <td>' . $val['items_order_number'] . '</td> <td>' . $val['items_code'] . '</td> <td>' . $val['items_name'] . '</td> <td>' . $val['items_description'] . '</td> <td>' . $val['items_qty'] . '</td> <td>' . $val['items_unit'] . '</td> <td>' . $val['items_warehouse_code'] . ' ' . $warehouseInfo['name'] . '</td> <td>' . $val['items_remark'] . '</td> <td>' . $itemInfo . '</td> </tr>'; } $itemsTable .= '</table>'; $mailContent = '<div>采购到货,请登录系统查看:</div> <div> <p><b>收货单号:</b>' . $receiveData['number'] . '</p> <p><b>收货日期:</b>' . $receiveData['date'] . '</p> <p><b>收货人:</b>' . $user_session->user_info['user_name'] . '</p> <p><b>描述:</b>' . $receiveData['description'] . '</p> <p><b>备注:</b>' . $receiveData['remark'] . '</p> </div><div>' . $itemsTable . '</div><hr>'; $mailData = array('type' => '通知', 'subject' => '到货通知 - ' . $receiveData['number'] . ' - ' . implode(', ', $supplierArr), 'cc' => $user_session->user_info['user_email'], 'content' => $mailContent, 'add_date' => $now, 'to' => implode(',', $noticeMails), 'user_id' => $user_id); try { // 记录邮件日志并发送邮件 //echo '<pre>';print_r($mailData);exit; $mail->send($mail->insert($mailData)); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); } echo Zend_Json::encode($result); exit; }
public function edititemsAction() { // 返回值数组 $result = array('success' => true, 'info' => '编辑成功'); $request = $this->getRequest()->getParams(); $now = date('Y-m-d H:i:s'); $user_session = new Zend_Session_Namespace('user'); $user_id = $user_session->user_info['user_id']; $json = json_decode($request['json']); $send_id = $json->send_id; $json_items = $json->items; $items_updated = $json_items->updated; $items_inserted = $json_items->inserted; $items_deleted = $json_items->deleted; $receive = new Erp_Model_Stock_receive(); $items = new Erp_Model_Purchse_Receiveitems(); $itemsSend = new Erp_Model_Sale_Receiveitemsordersale(); $stock = new Erp_Model_Stock_Stock(); $receiveData = $receive->getData(null, $send_id, '销售交货'); // 更新 if (count($items_updated) > 0) { foreach ($items_updated as $val) { $data = array('code' => $val->items_code, 'name' => $val->items_name, 'description' => $val->items_description, 'qty' => $val->items_qty, 'unit' => $val->items_unit, 'customer_code' => $val->items_customer_code, 'customer_description' => $val->items_customer_description, 'warehouse_code' => $val->items_warehouse_code, 'remark' => $val->items_remark, 'update_user' => $user_id, 'update_time' => $now); try { $items->update($data, "id = " . $val->items_id); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } } // 插入 if (count($items_inserted) > 0) { foreach ($items_inserted as $val) { $total = round($val->items_qty * $val->items_price, 2); $code = $val->items_code_internal != '' ? $val->items_code_internal : $val->items_code; $product_code = $val->items_code_internal != '' ? $val->items_code : ''; $data = array('receive_id' => $send_id, 'code' => $code, 'product_code' => $product_code, 'name' => $val->items_name, 'description' => $val->items_description, 'qty' => $val->items_qty, 'price' => $val->items_price, 'total' => $total, 'unit' => $val->items_unit, 'customer_code' => $val->items_customer_code, 'customer_description' => $val->items_customer_description, 'warehouse_code' => $val->items_warehouse_code, 'remark' => $val->items_remark, 'order_number' => $val->items_order_number, 'create_user' => $user_id, 'create_time' => $now, 'update_user' => $user_id, 'update_time' => $now); try { $receive_item_id = $items->insert($data); // 记录分拆数据 $itemData = array('receive_number' => $receiveData['number'], 'receive_item_id' => $receive_item_id, 'items_order_item_id' => $val->items_order_item_id, 'items_order_currency' => $val->items_order_currency, 'items_order_date' => $val->items_order_date, 'items_code' => $code, 'items_product_code' => $product_code, 'items_customer_code' => $val->items_customer_code, 'items_customer_description' => $val->items_customer_description, 'items_remark' => $val->items_remark, 'items_qty' => $val->items_qty, 'items_price' => $val->items_price, 'items_warehouse_code' => $val->items_warehouse_code, 'items_order_id' => $val->items_order_id, 'items_order_number' => $val->items_order_number); $this->saveItemDetails($itemData); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } } // 更新总计 $items->refreshReceiveTotal($send_id); if ($result['success']) { $member = new Admin_Model_Member(); $noticeMails = array(); $noticeUsers = array(); $noticeTo = $member->getMemberWithManagerByName('通知-销售交货'); foreach ($noticeTo as $n) { if ($n['email'] != '' && !in_array($n['user_id'], $noticeUsers)) { array_push($noticeMails, $n['email']); array_push($noticeUsers, $n['user_id']); } } if (count($noticeMails)) { $warehouse = new Erp_Model_Warehouse_Warehouse(); $title = '销售交货-' . $receiveData['transaction_type']; $mailContent = '<div><b>' . $title . '</b>,请登录系统查看:</div> <div> <p><b>单据号:</b>' . $receiveData['number'] . '</p> <p><b>制单员:</b>' . $user_session->user_info['user_name'] . '</p> <p><b>描述:</b>' . $receiveData['description'] . '</p> <p><b>备注:</b>' . $receiveData['remark'] . '</p> <p><b>时间:</b>' . $receiveData['create_time'] . '</p> </div><hr>'; $mailContent .= '<div><style type="text/css"> table.gridtable { font-family: verdana,arial,sans-serif; font-size:12px; color:#333333; border-width: 1px; border-color: #666666; border-collapse: collapse; } table.gridtable th { border-width: 1px; padding: 8px; border-style: solid; border-color: #666666; background-color: #dedede; } table.gridtable td { border-width: 1px; padding: 8px; border-style: solid; border-color: #666666; background-color: #ffffff; } .delete{ text-decoration: line-through; color: #FF0000; } .update{ font-weight: bold; color: #000093; } .inactive{ font-weight: bold; color: #999999; } </style><table class="gridtable"> <tr> <th>#</th> <th>内部型号 / 物料号</th> <th>名称</th> <th>描述</th> <th>数量</th> <th>单位</th> <th>客户产品型号</th> <th>客户产品描述</th> <th>交货仓位</th> <th>备注</th> </tr>'; $itemsData = $items->getData($send_id); $i = 0; foreach ($itemsData as $d) { $i++; $warehouseData = $warehouse->getInfoByCode($d['items_warehouse_code']); $warehouseInfo = $warehouseData["code"]; if (isset($warehouseData["name"])) { $warehouseInfo = $warehouseData["code"] . ' ' . $warehouseData["name"]; } $mailContent .= '<tr> <td>' . $i . '</td> <td>' . $d['items_code'] . '</td> <td>' . $d['items_name'] . '</td> <td>' . $d['items_description'] . '</td> <td>' . $d['items_qty'] . '</td> <td>' . $d['items_unit'] . '</td> <td>' . $d['items_customer_code'] . '</td> <td>' . $d['items_customer_description'] . '</td> <td>' . $warehouseInfo . '</td> <td>' . $d['items_remark'] . '</td> </tr>'; } $mailContent .= '</table></div><hr>'; $mailData = array('type' => '通知', 'subject' => $title, 'cc' => $user_session->user_info['user_email'], 'content' => $mailContent, 'add_date' => $now, 'to' => implode(',', $noticeMails), 'user_id' => $user_id); try { // 记录邮件日志并发送邮件 $mail = new Application_Model_Log_Mail(); $mail->send($mail->insert($mailData)); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); } } } echo Zend_Json::encode($result); exit; }
public function edititemsAction() { // 返回值数组 $result = array('success' => true, 'info' => '编辑成功'); $request = $this->getRequest()->getParams(); $now = date('Y-m-d H:i:s'); $user_session = new Zend_Session_Namespace('user'); $user_id = $user_session->user_info['user_id']; $json = json_decode($request['json']); $receive_id = $json->transfer_id; $json_items = $json->items; $items_updated = $json_items->updated; $items_inserted = $json_items->inserted; $items_deleted = $json_items->deleted; $receive = new Erp_Model_Stock_receive(); $items = new Erp_Model_Purchse_Receiveitems(); $stock = new Erp_Model_Stock_Stock(); $warehouse = new Erp_Model_Warehouse_Warehouse(); $receiveData = $receive->getData(null, $receive_id, '调拨'); // 更新 if (count($items_updated) > 0) { foreach ($items_updated as $val) { $data = array('code' => $val->items_code, 'name' => $val->items_name, 'description' => $val->items_description, 'qty' => $val->items_qty, 'unit' => $val->items_unit, 'warehouse_code' => $val->items_warehouse_code, 'warehouse_code_transfer' => $val->items_warehouse_code_transfer, 'remark' => $val->items_remark, 'update_user' => $user_id, 'update_time' => $now); try { $items->update($data, "id = " . $val->items_id); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } } // 插入 if (count($items_inserted) > 0) { foreach ($items_inserted as $val) { $total = round($val->items_qty * $val->items_price, 2); $data = array('receive_id' => $receive_id, 'code' => $val->items_code, 'name' => $val->items_name, 'description' => $val->items_description, 'qty' => $val->items_qty, 'price' => $val->items_price, 'total' => $total, 'unit' => $val->items_unit, 'warehouse_code' => $val->items_warehouse_code, 'warehouse_code_transfer' => $val->items_warehouse_code_transfer, 'remark' => $val->items_remark, 'create_user' => $user_id, 'create_time' => $now, 'update_user' => $user_id, 'update_time' => $now); try { $receive_item_id = $items->insert($data); // 记录库存数据 $stockData = array('code' => $val->items_code, 'warehouse_code' => $val->items_warehouse_code_transfer, 'qty' => $val->items_qty, 'total' => $total, 'create_user' => $user_id, 'create_time' => $now, 'doc_type' => '调拨收货', 'transaction_type' => $receiveData['transaction_type'], 'doc_number' => $receiveData['number']); $stock->insert($stockData); $qty = round(0 - $val->items_qty, 4); $total = round(0 - $total, 2); // 记录库存数据 $stockData = array('code' => $val->items_code, 'warehouse_code' => $val->items_warehouse_code, 'qty' => $qty, 'total' => $total, 'create_user' => $user_id, 'create_time' => $now, 'doc_type' => '调拨发货', 'doc_number' => $receiveData['number']); $stock->insert($stockData); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } } // 更新总计 $items->refreshReceiveTotal($receive_id); if ($result['success']) { // 转储通知(针对从待检仓转出) if ($receiveData['transaction_type'] == '外购入库' && $receiveData['order_id'] != '') { // 计算收货入库数量(订单、申请) $receiveModel = new Erp_Model_Stock_Receive(); $receiveModel->correctInStockQty($receive_id); $member = new Admin_Model_Member(); $noticeMails = array(); $noticeUsers = array(); $noticeTo = $member->getMemberWithManagerByName('外购入库'); // 通知:外购入库 foreach ($noticeTo as $n) { if ($n['email'] != '' && !in_array($n['user_id'], $noticeUsers)) { array_push($noticeMails, $n['email']); array_push($noticeUsers, $n['user_id']); } } $noticeTo = $member->getMemberWithManagerByName('库房'); // 通知:库房 foreach ($noticeTo as $n) { if ($n['email'] != '' && !in_array($n['user_id'], $noticeUsers)) { array_push($noticeMails, $n['email']); array_push($noticeUsers, $n['user_id']); } } // 通知:QA $noticeTo = $member->getMemberWithManagerByName('QA'); foreach ($noticeTo as $n) { if ($n['email'] != '' && !in_array($n['user_id'], $noticeUsers)) { array_push($noticeMails, $n['email']); array_push($noticeUsers, $n['user_id']); } } // 通知:外购入库通知 $noticeTo = $member->getMemberWithManagerByName('外购入库通知'); foreach ($noticeTo as $n) { if ($n['email'] != '' && !in_array($n['user_id'], $noticeUsers)) { array_push($noticeMails, $n['email']); array_push($noticeUsers, $n['user_id']); } } // 获取采购订单信息 $order = new Erp_Model_Purchse_Order(); $order_data = $order->getData(null, $receiveData['order_id']); // 获取采购订单相关参与人员 $receive_items_order = new Erp_Model_Purchse_Receiveitemsorder(); $relatedUserInfo = $receive_items_order->getReqRelatedUsers(array($order_data['number'])); foreach ($relatedUserInfo as $n) { if ($n['email'] != '' && !in_array($n['user_id'], $noticeUsers)) { array_push($noticeMails, $n['email']); array_push($noticeUsers, $n['user_id']); } } $mail = new Application_Model_Log_Mail(); $itemsTable = '<style type="text/css"> table.gridtable { font-family: verdana,arial,sans-serif; font-size:11px; color:#333333; border-width: 1px; border-color: #666666; border-collapse: collapse; } table.gridtable th { border-width: 1px; padding: 8px; border-style: solid; border-color: #666666; background-color: #dedede; } table.gridtable td { border-width: 1px; padding: 8px; border-style: solid; border-color: #666666; background-color: #ffffff; } </style><table class="gridtable"><tr> <th>#</th> <th>物料号</th> <th>物料名称</th> <th>物料描述</th> <th>数量</th> <th>单位</th> <th>出库仓位</th> <th>入库仓位</th> <th>备注</th> </tr>'; $i = 0; foreach ($items_inserted as $val) { $i++; $warehouseInfo = $warehouse->getInfoByCode($val->items_warehouse_code); $warehouseTransferInfo = $warehouse->getInfoByCode($val->items_warehouse_code_transfer); $stockQty = $stock->getStockQty($val->items_code, array($val->items_warehouse_code)); $stockTransferQty = $stock->getStockQty($val->items_code, array($val->items_warehouse_code_transfer)); $itemsTable .= '<tr> <td>' . $i . '</td> <td>' . $val->items_code . '</td> <td>' . $val->items_name . '</td> <td>' . $val->items_description . '</td> <td>' . $val->items_qty . '</td> <td>' . $val->items_unit . '</td> <td>' . $val->items_warehouse_code . ' ' . $warehouseInfo['name'] . ' [' . $stockQty['total'] . ']</td> <td>' . $val->items_warehouse_code_transfer . ' ' . $warehouseTransferInfo['name'] . ' [' . $stockTransferQty['total'] . ']</td> <td>' . $val->items_remark . '</td> </tr>'; } $itemsTable .= '</table>'; $title = '库存调拨 - ' . $receiveData['transaction_type'] . ' [' . $order_data['supplier_code'] . ' ' . $order_data['supplier_ename'] . ']'; $mailContent = '<div>' . $title . ',请登录系统查看:</div> <div> <p><b>单据号:</b>' . $receiveData['number'] . '</p> <p><b>日期:</b>' . $receiveData['date'] . '</p> <p><b>采购订单:</b>' . $order_data['number'] . '</p> <p><b>制单人:</b>' . $user_session->user_info['user_name'] . '</p> <p><b>描述:</b>' . $receiveData['description'] . '</p> <p><b>备注:</b>' . $receiveData['remark'] . '</p> </div><div>' . $itemsTable . '</div><hr>'; $mailData = array('type' => '通知', 'subject' => $title, 'cc' => $user_session->user_info['user_email'], 'content' => $mailContent, 'add_date' => $now, 'to' => implode(',', $noticeMails), 'user_id' => $user_id); try { // 记录邮件日志并发送邮件 $mail->send($mail->insert($mailData)); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); } } else { $member = new Admin_Model_Member(); $noticeMails = array(); $noticeUsers = array(); $noticeTo = $member->getMemberWithManagerByName('通知-库存交易-调拨'); foreach ($noticeTo as $n) { if ($n['email'] != '' && !in_array($n['user_id'], $noticeUsers)) { array_push($noticeMails, $n['email']); array_push($noticeUsers, $n['user_id']); } } if (count($noticeMails)) { $warehouse = new Erp_Model_Warehouse_Warehouse(); $title = '库存交易-调拨-' . $receiveData['transaction_type']; $mailContent = '<div><b>' . $title . '</b>,请登录系统查看:</div> <div> <p><b>单据号:</b>' . $receiveData['number'] . '</p> <p><b>制单员:</b>' . $user_session->user_info['user_name'] . '</p> <p><b>描述:</b>' . $receiveData['description'] . '</p> <p><b>备注:</b>' . $receiveData['remark'] . '</p> <p><b>时间:</b>' . $receiveData['create_time'] . '</p> </div><hr>'; $mailContent .= '<div><style type="text/css"> table.gridtable { font-family: verdana,arial,sans-serif; font-size:12px; color:#333333; border-width: 1px; border-color: #666666; border-collapse: collapse; } table.gridtable th { border-width: 1px; padding: 8px; border-style: solid; border-color: #666666; background-color: #dedede; } table.gridtable td { border-width: 1px; padding: 8px; border-style: solid; border-color: #666666; background-color: #ffffff; } .delete{ text-decoration: line-through; color: #FF0000; } .update{ font-weight: bold; color: #000093; } .inactive{ font-weight: bold; color: #999999; } </style><table class="gridtable"> <tr> <th>#</th> <th>物料号</th> <th>名称</th> <th>描述</th> <th>数量</th> <th>单位</th> <th>出库仓位</th> <th>入货仓位</th> <th>备注</th> </tr>'; $itemsData = $items->getData($receive_id); $i = 0; foreach ($itemsData as $d) { $i++; $warehouseData = $warehouse->getInfoByCode($d['items_warehouse_code']); $warehouseInfo = $warehouseData["code"]; if (isset($warehouseData["name"])) { $warehouseInfo = $warehouseData["code"] . ' ' . $warehouseData["name"]; } $warehouseTransferData = $warehouse->getInfoByCode($d['items_warehouse_code_transfer']); $warehouseTransferInfo = $warehouseTransferData["code"]; if (isset($warehouseTransferData["name"])) { $warehouseTransferInfo = $warehouseTransferData["code"] . ' ' . $warehouseTransferData["name"]; } $mailContent .= '<tr> <td>' . $i . '</td> <td>' . $d['items_code'] . '</td> <td>' . $d['items_name'] . '</td> <td>' . $d['items_description'] . '</td> <td>' . $d['items_qty'] . '</td> <td>' . $d['items_unit'] . '</td> <td>' . $warehouseInfo . '</td> <td>' . $warehouseTransferInfo . '</td> <td>' . $d['items_remark'] . '</td> </tr>'; } $mailContent .= '</table></div><hr>'; $mailData = array('type' => '通知', 'subject' => $title, 'cc' => $user_session->user_info['user_email'], 'content' => $mailContent, 'add_date' => $now, 'to' => implode(',', $noticeMails), 'user_id' => $user_id); try { // 记录邮件日志并发送邮件 $mail = new Application_Model_Log_Mail(); $mail->send($mail->insert($mailData)); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); } } } } echo Zend_Json::encode($result); exit; }