Exemple #1
0
 public function getorderAction()
 {
     // 请求参数
     $request = $this->getRequest()->getParams();
     $option = isset($request['option']) ? $request['option'] : 'data';
     $condition = array('key' => isset($request['key']) ? $request['key'] : '', 'state' => isset($request['state']) && is_numeric($request['state']) ? $request['state'] : null, 'date_from' => isset($request['date_from']) ? $request['date_from'] : null, 'date_to' => isset($request['date_to']) ? $request['date_to'] : null, 'complete' => isset($request['complete']) && $request['complete'] != 'null' ? $request['complete'] : 1, 'type' => isset($request['type']) && $request['type'] != 'null' ? $request['type'] : null, 'dept' => isset($request['dept']) && $request['dept'] != 'null' ? $request['dept'] : null, 'buyer' => isset($request['buyer']) && $request['buyer'] != 'null' ? $request['buyer'] : null, 'page' => isset($request['page']) ? $request['page'] : 1, 'limit' => isset($request['limit']) ? $request['limit'] : 0, 'option' => $option);
     $order = new Erp_Model_Purchse_Order();
     $data = $order->getOrderStatistics($condition);
     if ($option == 'csv') {
         $this->view->layout()->disableLayout();
         $this->_helper->viewRenderer->setNoRender(true);
         $h = new Application_Model_Helpers();
         $h->exportCsv($data, '采购订单统计');
     } else {
         echo Zend_Json::encode($data);
     }
     exit;
 }
Exemple #2
0
    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;
    }
Exemple #3
0
    /**
     * 保存采购申请表体
     */
    public function edititemsAction()
    {
        // 返回值数组
        $result = array('success' => true, 'info' => '编辑成功');
        $request = $this->getRequest()->getParams();
        $type = isset($request['operate']) ? $request['operate'] : '';
        // 操作类别
        $typeArr = array('new' => '新建', 'edit' => '修改', 'transfer' => '变更');
        $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']);
        $order_id = $json->order_id;
        $transfer_id = $json->transfer_id;
        $order_id = $json->order_id;
        $json_items = $json->items;
        $items_updated = $json_items->updated;
        $items_inserted = $json_items->inserted;
        $items_deleted = $json_items->deleted;
        $items = new Erp_Model_Purchse_Orderitems();
        $itemsreq = new Erp_Model_Purchse_Orderitemsreq();
        $transfer_items = new Erp_Model_Purchse_Transferorderitems();
        // 更新
        if (count($items_updated) > 0) {
            foreach ($items_updated as $val) {
                $active = $val->items_active ? 1 : 0;
                $total = round($val->items_qty * $val->items_price, 4);
                $data = array('active' => $active, 'req_number' => $val->items_req_number, 'code' => $val->items_code, 'name' => $val->items_name, 'description' => $val->items_description, 'supplier_code' => $val->items_supplier_code, 'supplier_codename' => $val->items_supplier_codename, 'supplier_description' => $val->items_supplier_description, 'qty' => $val->items_qty, 'unit' => $val->items_unit, 'price' => $val->items_price, 'total' => $total, 'warehouse_code' => $val->items_warehouse_code, 'request_date' => $val->items_request_date, 'dept_id' => $val->items_dept_id, 'project_info' => $val->items_project_info, 'remark' => $val->items_remark);
                try {
                    if ($type == 'transfer') {
                        $data['req_item_id'] = $val->items_req_item_id;
                        $data['order_id'] = $order_id;
                        $data['transfer_id'] = $transfer_id;
                        $data['order_item_id'] = $val->items_id;
                        $data['transfer_type'] = 'update';
                        $transfer_items->insert($data);
                    } else {
                        $data['update_user'] = $user_id;
                        $data['update_time'] = $now;
                        $items->update($data, "id = " . $val->items_id);
                        // 保存分拆订单项信息
                        $this->saveSplitItem('update', $val->items_id, $val->items_req_item_id, $val->items_qty, $val->items_code, $active);
                    }
                } 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) {
                $active = $val->items_active ? 1 : 0;
                $total = round($val->items_qty * $val->items_price, 4);
                $data = array('order_id' => $order_id, 'active' => $active, 'req_number' => $val->items_req_number, 'code' => $val->items_code, 'name' => $val->items_name, 'description' => $val->items_description, 'supplier_code' => $val->items_supplier_code, 'supplier_codename' => $val->items_supplier_codename, 'supplier_description' => $val->items_supplier_description, 'qty' => $val->items_qty, 'unit' => $val->items_unit, 'price' => $val->items_price, 'total' => $total, 'warehouse_code' => $val->items_warehouse_code, 'request_date' => $val->items_request_date, 'dept_id' => $val->items_dept_id, 'project_info' => $val->items_project_info, 'remark' => $val->items_remark);
                try {
                    if ($type == 'transfer') {
                        $data['transfer_id'] = $transfer_id;
                        $data['order_item_id'] = $val->items_id;
                        $data['req_item_id'] = $val->items_req_item_id;
                        $data['req_qty'] = $val->items_req_qty;
                        $data['transfer_type'] = 'add';
                        $transfer_items->insert($data);
                    } else {
                        $data['create_user'] = $user_id;
                        $data['create_time'] = $now;
                        $data['update_user'] = $user_id;
                        $data['update_time'] = $now;
                        $order_item_id = $items->insert($data);
                        $this->saveSplitItem('insert', $order_item_id, $val->items_req_item_id, $val->items_req_qty, $val->items_code);
                    }
                } catch (Exception $e) {
                    $result['success'] = false;
                    $result['info'] = $e->getMessage();
                    echo Zend_Json::encode($result);
                    exit;
                }
            }
        }
        // 删除
        if (count($items_deleted) > 0) {
            foreach ($items_deleted as $val) {
                try {
                    if ($type == 'transfer') {
                        $active = $val->items_active ? 1 : 0;
                        $line_total = round($val->items_qty * $val->items_price, 4);
                        $data = array('active' => $active, 'transfer_type' => 'delete', 'transfer_id' => $transfer_id, 'order_item_id' => $val->items_id, 'req_number' => $val->items_req_number, 'code' => $val->items_code, 'name' => $val->items_name, 'description' => $val->items_description, 'supplier_code' => $val->items_supplier_code, 'supplier_codename' => $val->items_supplier_codename, 'supplier_description' => $val->items_supplier_description, 'qty' => $val->items_qty, 'unit' => $val->items_unit, 'price' => $val->items_price, 'total' => $total, 'warehouse_code' => $val->items_warehouse_code, 'request_date' => $val->items_request_date, 'dept_id' => $val->items_dept_id, 'project_info' => $val->items_project_info, 'remark' => $val->items_remark);
                        $transfer_items->insert($data);
                    } else {
                        $items->delete("id = " . $val->items_id);
                        // 清除订单项对应的申请项数据
                        $itemsreq->delete("order_item_id = " . $val->items_id);
                        $this->saveSplitItem('delete', $val->items_id, $val->items_req_item_id, $val->items_req_qty, $val->items_code);
                    }
                } catch (Exception $e) {
                    $result['success'] = false;
                    $result['info'] = $e->getMessage();
                    echo Zend_Json::encode($result);
                    exit;
                }
            }
        }
        // 更新订单项状态
        $activeItemsRes = $items->fetchAll("active = 1 and order_id = " . $order_id);
        if ($activeItemsRes->count() > 0) {
            $activeItems = $activeItemsRes->toArray();
            for ($j = 0; $j < count($activeItems); $j++) {
                $itemsreq->update(array('active' => 1), "order_item_id = " . $activeItems[$j]['id']);
            }
        }
        // 更新采购申请总计
        if ($type != 'transfer') {
            $items->refreshOrderTotal($order_id);
        }
        $order = new Erp_Model_Purchse_Order();
        $order_data = $order->getData(null, $order_id);
        // 保存成功,进入审批流程
        if ($result['success']) {
            // 根据流程ID获取阶段信息
            $flow = new Admin_Model_Flow();
            $flowData = $flow->fetchRow("id = " . $order_data['order_flow_id'])->toArray();
            // 获取审核阶段
            $step = new Admin_Model_Step();
            $stepIds = $flowData['step_ids'];
            $stepArr = explode(',', $stepIds);
            $review = new Dcc_Model_Review();
            $review->delete("type = 'purchse_order_add' and file_id = " . $order_id);
            $mailTo = null;
            $i = 0;
            $help = new Application_Model_Helpers();
            // 根据阶段信息初始化审批流程,并向第一阶段审核人发送邮件
            foreach ($stepArr as $s) {
                $stepData = $step->fetchRow("id = " . $s)->toArray();
                $step_user = $stepData['user'] != '' ? $stepData['user'] : null;
                $step_role = $stepData['dept'] != '' ? $stepData['dept'] : null;
                $employeeArr = $help->getReviewEmployee($step_user, $step_role);
                $employeeIdArr = $employeeArr['id'];
                $employeeIds = implode(',', $employeeIdArr);
                $reviewData = array('type' => 'purchse_order_add', 'file_id' => $order_id, 'step_name' => $stepData['step_name'], 'plan_user' => $employeeIds, 'plan_dept' => $step_role, 'method' => $stepData['method'], 'return' => $stepData['return']);
                $review->insert($reviewData);
                // 第一阶段发送邮件通知
                if ($i == 0) {
                    $mailTo = $employeeIdArr;
                }
                $i++;
            }
            if ($mailTo) {
                // 获取币种信息
                $currency = new Erp_Model_Setting_Currency();
                $currencyInfo = $currency->getInfoByCode($order_data['currency']);
                $total = $order_data['total'];
                if ($order_data['currency_rate'] != 1) {
                    $total = $order_data['forein_total'];
                }
                $mailContent = '<div>新建采购订单,请登录系统查看:</div>
                            <div>
                            <p><b>订单号:</b>' . $order_data['number'] . '</p>
                            <p><b>采购员:</b>' . $user_session->user_info['user_name'] . '</p>
                            <p><b>类别:</b>' . $order_data['type'] . '</p>
                            <p><b>金额:</b><a style="color: #467500;font-weight: bold;">' . $currencyInfo['symbol'] . $total . '</a></p>
                            <p><b>描述:</b>' . $order_data['description'] . '</p>
                            <p><b>备注:</b>' . $order_data['remark'] . '</p>
                            <p><b>申请时间:</b>' . $order_data['create_time'] . '</p>
                            <p><b>更新时间:</b>' . $order_data['update_time'] . '</p>
                            </div><hr>';
                $transferContent = '';
                if ($type == 'transfer') {
                    $transferContent .= '<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>
                			<th>备注</th>
                			</tr>';
                    $i = 1;
                    foreach ($items_inserted as $val) {
                        $active = $val->items_active ? '是' : '否';
                        $transferContent .= '<tr>
                			<td>' . $i . '</td>
                			<td>新增</td>
                			<td>' . $active . '</td>
                			<td>' . $val->items_code . '</td>
                			<td>' . $val->items_name . '</td>
                			<td>' . $val->items_description . '</td>
                			<td>' . $val->items_qty . '</td>
                			<td>0</td>
                			<td>' . date('Y-m-d', strtotime($val->items_request_date)) . '</td>
                			<td>' . $val->items_project_info . '</td>
                			<td>' . $val->items_remark . '</td>
                			</tr>';
                        $i++;
                    }
                    foreach ($items_updated as $val) {
                        $tr = '<tr>';
                        if (!$val->items_active) {
                            $tr = '<tr class="inactive">';
                        } else {
                            $tr = '<tr class="update">';
                        }
                        $active = $val->items_active ? '是' : '否';
                        $transferContent .= $tr . '
                			<td>' . $i . '</td>
                			<td>更新</td>
                			<td>' . $active . '</td>
                			<td>' . $val->items_code . '</td>
                			<td>' . $val->items_name . '</td>
                			<td>' . $val->items_description . '</td>
                			<td>' . $val->items_qty . '</td>
                			<td>' . $val->items_qty_receive . '</td>
                			<td>' . $val->items_request_date . '</td>
                			<td>' . $val->items_project_info . '</td>
                			<td>' . $val->items_remark . '</td>
                			</tr>';
                        $i++;
                    }
                    foreach ($items_deleted as $val) {
                        $active = $val->items_active ? '是' : '否';
                        $transferContent .= '<tr class="delete">
                			<td>' . $i . '</td>
                			<td>删除</td>
                			<td>' . $active . '</td>
                			<td>' . $val->items_code . '</td>
                			<td>' . $val->items_name . '</td>
                			<td>' . $val->items_description . '</td>
                			<td>' . $val->items_qty . '</td>
                			<td>0</td>
                			<td>' . $val->items_request_date . '</td>
                			<td>' . $val->items_project_info . '</td>
                			<td>' . $val->items_remark . '</td>
                			</tr>';
                        $i++;
                    }
                    $transferContent .= '</table></div>';
                }
                $mailData = array('type' => '消息', 'subject' => '采购订单-' . $typeArr[$type], 'cc' => $user_session->user_info['user_email'], 'content' => $mailContent . $transferContent, 'add_date' => $now);
                if ($transferContent != '') {
                    $transfer = new Erp_Model_Purchse_Transfer();
                    $transfer->update(array('transfer_content' => $transferContent), "id = " . $transfer_id);
                }
                $result = $help->sendMailToStep($mailTo, $mailData);
            }
        }
        echo Zend_Json::encode($result);
        exit;
    }
Exemple #4
0
 public function getReqStatistics($condition = array())
 {
     $data = array();
     $sql = $this->select()->setIntegrityCheck(false)->from(array('t1' => $this->_name), array('req_active' => 'active', 'req_state' => new Zend_Db_Expr("case when t1.state = 0 then '审核中' when t1.state = 1 then '拒绝' else '批准' end"), 'req_number' => 'number', 'req_dept_id' => 'dept_id', 'req_release_time' => 'release_time', 'req_create_time' => 'create_time', 'req_remark' => 'remark', 'req_reason' => 'reason', 'req_type_id' => 'type_id'))->joinLeft(array('t2' => $this->_dbprefix . 'user'), "t1.create_user = t2.id", array())->joinLeft(array('t3' => $this->_dbprefix . 'employee'), "t2.employee_id = t3.id", array('req_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('req_updater' => 'cname'))->joinLeft(array('t6' => $this->_dbprefix . 'employee_dept'), "t1.dept_id = t6.id", array('req_dept' => 'name'))->joinLeft(array('t7' => $this->_dbprefix . 'erp_pur_type'), "t1.type_id = t7.id", array('req_type' => 'name'))->joinLeft(array('t8' => $this->_dbprefix . 'erp_pur_req_items'), "t1.id = t8.req_id")->joinLeft(array('t9' => $this->_dbprefix . 'employee_dept'), "t8.dept_id = t9.id", array('dept' => 'name'))->joinLeft(array('t10' => $this->_dbprefix . 'erp_pur_order_items_req'), "t10.req_item_id = t8.id and t10.active = 1", array('req_item_id', 'order_item_ids' => new Zend_Db_Expr("group_concat(t10.order_item_id)"), 'qty_order' => new Zend_Db_Expr("sum(t10.qty)")))->joinLeft(array('t11' => $this->_dbprefix . 'erp_pur_order_items'), "t10.order_item_id = t11.id", array('order_item_id' => 'id', 'delivery_date', 'delivery_date_remark'))->joinLeft(array('t14' => $this->_dbprefix . 'erp_pur_order'), "t11.order_id = t14.id", array('order_number' => new Zend_Db_Expr("group_concat(t14.number)")))->joinLeft(array('t12' => $this->_dbprefix . 'user'), "t1.apply_user = t12.id", array())->joinLeft(array('t13' => $this->_dbprefix . 'employee'), "t12.employee_id = t13.id", array('req_applier' => 'cname'))->group("t8.id")->order(array('t1.number desc', 't1.create_time desc'));
     // 状态
     if ($condition['state'] != null) {
         if ($condition['state'] == 3) {
             $sql->where("t1.active = 0");
         } else {
             $sql->where("t1.state = " . $condition['state']);
         }
     }
     // 申请人
     if ($condition['applier']) {
         $sql->where("t3.cname like '%" . $condition['applier'] . "%' or t3.ename like '%" . $condition['applier'] . "%'");
     }
     // 日前从
     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['type']) {
         $type = json_decode($condition['type']);
         if (count($type)) {
             $type_con = "t1.type_id = " . $type[0];
             for ($i = 1; $i < count($type); $i++) {
                 $type_con .= " or t1.type_id = " . $type[$i];
             }
             $sql->where($type_con);
         }
     }
     // 需求部门
     if ($condition['dept']) {
         $dept = json_decode($condition['dept']);
         if (count($dept)) {
             $dept_con = "t1.dept_id = " . $dept[0];
             for ($i = 1; $i < count($dept); $i++) {
                 $dept_con .= " or t1.dept_id = " . $dept[$i];
             }
             $sql->where($dept_con);
         }
     }
     if ($condition['key']) {
         $sql->where("t1.number like '%" . $condition['key'] . "%' or t1.remark like '%" . $condition['key'] . "%' or t1.reason like '%" . $condition['key'] . "%' or t3.cname like '%" . $condition['key'] . "%' or t3.ename like '%" . $condition['key'] . "%' or t7.name like '%" . $condition['key'] . "%' or t8.code like '%" . $condition['key'] . "%' or t8.name like '%" . $condition['key'] . "%' or t8.description like '%" . $condition['key'] . "%'");
     }
     $total = $this->fetchAll($sql)->count();
     if ($condition['option'] != 'csv') {
         $sql->limitPage($condition['page'], $condition['limit']);
     }
     $data = $this->fetchAll($sql)->toArray();
     $items_req = new Erp_Model_Purchse_Orderitemsreq();
     $order = new Erp_Model_Purchse_Order();
     $operateModel = new Application_Model_Log_Operate();
     $receiveModel = new Erp_Model_Purchse_Reqitemsreceived();
     for ($i = 0; $i < count($data); $i++) {
         $data[$i]['delivery_reply_log'] = '';
         // 入库日志
         $data[$i]['in_stock_qty'] = 0;
         $data[$i]['in_stock_info'] = '';
         if ($data[$i]['req_item_id']) {
             $in_stock_info = $receiveModel->getReceivedInfo('req', $data[$i]['req_item_id']);
             $data[$i]['in_stock_qty'] = $in_stock_info['qty'];
             $data[$i]['in_stock_info'] = implode(',', $in_stock_info['info']);
         }
         // 交期回复日志
         if ($data[$i]['delivery_date'] != '' || $data[$i]['delivery_date_remark'] != '') {
             $logInfo = array();
             $log = $operateModel->getLogByOperateAndTargetId('采购交期回复', $data[$i]['order_item_id']);
             foreach ($log as $l) {
                 $content = Zend_Json::decode($l['content']);
                 $logText = $content['time'] . ' [' . $content['delivery_date'] . '] [' . $content['delivery_date_remark'] . '] ' . $content['user'];
                 array_push($logInfo, $logText);
             }
             $data[$i]['delivery_reply_log'] = implode(',', $logInfo);
         }
         // 获取采购订单数量(合并下单的申请分拆显示)
         $data[$i]['req_info'] = '';
         $data[$i]['receive_info'] = '';
         $data[$i]['receive_qty'] = 0;
         $data[$i]['order_info'] = '';
         if ($data[$i]['order_item_ids'] != '') {
             $item_ids = explode(',', $data[$i]['order_item_ids']);
             $req_item_data = $order->getOrderQty($item_ids, $data[$i]['req_item_id']);
             $orderInfoArr = array();
             $receiveInfoArr = array();
             //echo '<pre>';print_r($req_item_data);exit;
             foreach ($req_item_data as $req_info) {
                 foreach ($req_info['receive_data'] as $r) {
                     array_push($receiveInfoArr, $r['number'] . ' [' . $r['qty'] . '] [' . $r['time'] . ']');
                     $data[$i]['receive_qty'] += $r['qty'];
                 }
                 array_push($orderInfoArr, $req_info['number'] . ' [' . $req_info['qty'] . '] [' . $req_info['time'] . ']');
             }
             $data[$i]['order_info'] = implode(',', $orderInfoArr);
             $data[$i]['receive_info'] = implode(',', $receiveInfoArr);
         }
         $data[$i]['qty_left'] = $data[$i]['qty'] - $data[$i]['qty_order'];
         if ($data[$i]['req_active'] == 0) {
             $data[$i]['req_state'] = '取消';
         }
     }
     //echo '<pre>';print_r($data);exit;
     if ($condition['option'] == 'csv') {
         $data_csv = array();
         $title = array('cnt' => '#', 'active' => '启用', 'req_number' => '申请单号', 'req_type' => '类别', 'req_dept' => '申请部门', 'dept' => '需求部门', 'code' => '物料号', 'qty' => '申请数量', 'qty_order' => '下单数量', 'order_info' => '采购订单', 'receive_qty' => '到货数量', 'receive_info' => '到货信息', 'in_stock_qty' => '入库数量', 'in_stock_info' => '入库信息', 'qty_left' => '未下单数量', 'date_req' => '需求日期', 'delivery_date' => '预计交期', 'delivery_date_remark' => '交期备注', 'delivery_reply_log' => '交期回复日志', 'name' => '名称', 'description' => '描述', 'model' => '型号', 'order_req_num' => '订货产品出库申请号', 'customer_address' => '客户收件人地址简码', 'customer_aggrement' => '客户合同号', 'remark' => '备注', 'req_creater' => '制单人', 'req_applier' => '申请人', 'req_reason' => '申请事由', 'project_info' => '项目信息', 'req_remark' => '申请备注', 'req_create_date' => '申请日期', 'req_create_time' => '申请时间', 'req_release_date' => '批准日期', 'req_release_time' => '批准时间');
         array_push($data_csv, $title);
         $i = 0;
         foreach ($data as $d) {
             $i++;
             $info = array('cnt' => $i, 'active' => $d['active'] == 1 ? '是' : '否', 'req_number' => $d['req_number'], 'req_type' => $d['req_type'], 'req_dept' => $d['req_dept'], 'dept' => $d['dept'], 'code' => $d['code'], 'qty' => $d['qty'], 'qty_order' => $d['qty_order'], 'order_info' => $d['order_info'], 'receive_qty' => $d['receive_qty'], 'receive_info' => $d['receive_info'], 'in_stock_qty' => $d['in_stock_qty'], 'in_stock_info' => $d['in_stock_info'], 'qty_left' => $d['qty_left'], 'date_req' => $d['date_req'], 'delivery_date' => $d['delivery_date'], 'delivery_date_remark' => $d['delivery_date_remark'], 'delivery_reply_log' => $d['delivery_reply_log'], 'name' => $d['name'], 'description' => $d['description'], 'model' => $d['model'], 'order_req_num' => isset($d['order_req_num']) ? $d['order_req_num'] : '', 'customer_address' => $d['customer_address'], 'customer_aggrement' => $d['customer_aggrement'], 'remark' => $d['remark'], 'req_creater' => $d['req_creater'], 'req_applier' => $d['req_applier'], 'req_reason' => $d['req_reason'], 'project_info' => $d['project_info'], 'req_remark' => $d['req_remark'], 'req_create_date' => $d['req_create_time'] != '' ? date('Y-m-d', strtotime($d['req_create_time'])) : '', 'req_create_time' => $d['req_create_time'] != '' ? date('H:i:s', strtotime($d['req_create_time'])) : '', 'req_release_date' => $d['req_release_time'] != '' ? date('Y-m-d', strtotime($d['req_release_time'])) : '', 'req_release_time' => $d['req_release_time'] != '' ? date('H:i:s', strtotime($d['req_release_time'])) : '');
             array_push($data_csv, $info);
         }
         return $data_csv;
     }
     return array('total' => $total, 'rows' => $data);
 }
Exemple #5
0
    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;
    }
Exemple #6
0
 public function refreshOrderTotal($order_id)
 {
     $data = array('total' => 0, 'total_tax' => 0, 'total_no_tax' => 0, 'forein_total' => 0, 'forein_total_tax' => 0, 'forein_total_no_tax' => 0);
     $total = 0;
     if ($order_id) {
         $dataTmp = $this->fetchAll("order_id = " . $order_id);
         if ($dataTmp->count() > 0) {
             $items = $dataTmp->toArray();
             foreach ($items as $item) {
                 $total += $item['total'];
             }
         }
     }
     $order = new Erp_Model_Purchse_Order();
     $orderData = $order->getData(null, $order_id);
     // 当单价不含税时,需要根据实时税率计算税金及含税价
     if ($orderData['price_tax'] == 0) {
         $data['total_tax'] = $total * $orderData['tax_rate'];
         // 税金
         $data['total_no_tax'] = $total;
         // 不含税金额
         $data['total'] = $data['total_no_tax'] + $data['total_tax'];
         // 含税金额
     } else {
         $data['total_no_tax'] = $total / (1 + $orderData['tax_rate']);
         $data['total_tax'] = $total - $data['total_no_tax'];
         $data['total'] = $total;
     }
     // 如果不是本币(汇率不为1),则需要将外币换算为本币
     if ($orderData['currency_rate'] != 1) {
         $data['forein_total'] = $data['total'];
         $data['forein_total_no_tax'] = $data['total_no_tax'];
         $data['forein_total_tax'] = $data['total_tax'];
         $data['total'] = $data['forein_total'] * $orderData['currency_rate'];
         $data['total_no_tax'] = $data['forein_total_no_tax'] * $orderData['currency_rate'];
         $data['total_tax'] = $data['forein_total_tax'] * $orderData['currency_rate'];
     }
     $order->update($data, "id = " . $order_id);
 }
    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;
    }