Exemplo n.º 1
0
 public function deleteAction()
 {
     $result = array('success' => true, 'info' => '删除成功!');
     $request = $this->getRequest()->getParams();
     $id = isset($request['id']) ? $request['id'] : null;
     if ($id) {
         $now = date('Y-m-d H:i:s');
         $user_session = new Zend_Session_Namespace('user');
         $user_id = $user_session->user_info['user_id'];
         $order = new Erp_Model_Sale_Order();
         $order->update(array('active' => 0, 'deleted' => 1, 'update_user' => $user_id, 'update_time' => $now), "deleted = 0 and id = " . $id);
         // 更新订单项状态(申请信息:用于扣减下单数量)
         $orderItems = new Erp_Model_Purchse_Orderitems();
         $orderItems->update(array('active' => 0), "order_id = " . $id);
     } else {
         $result['success'] = false;
         $result['info'] = '订单号错误,删除失败!';
     }
     echo Zend_Json::encode($result);
     exit;
 }
Exemplo n.º 2
0
 public function replydeliverydateAction()
 {
     // 返回值数组
     $result = array('success' => true, 'info' => '');
     $request = $this->getRequest()->getParams();
     $id = isset($request['id']) ? $request['id'] : null;
     $date = isset($request['date']) && $request['date'] != '' ? $request['date'] : null;
     $remark = isset($request['remark']) ? $request['remark'] : null;
     if ($id) {
         $item = new Erp_Model_Purchse_Orderitems();
         $itemData = $item->fetchRow("id = " . $id)->toArray();
         $user_session = new Zend_Session_Namespace('user');
         $user_id = $user_session->user_info['user_id'];
         $user_name = $user_session->user_info['user_name'];
         $now = date('Y-m-d H:i:s');
         $itemInfo = $item->fetchRow("id = " . $id)->toArray();
         $updateData = array('delivery_date_remark' => $remark);
         if ($itemInfo['delivery_date'] != $date) {
             $updateData['delivery_date'] = $date;
             $updateData['delivery_date_update_time'] = $now;
             $params = Zend_Json::encode(array('code' => $itemData['code'], 'name' => $itemData['name'], 'description' => $itemData['description'], 'delivery_date' => $date, 'delivery_date_remark' => $remark, 'user' => $user_name, 'time' => $now));
             $data = array('user_id' => $user_id, 'operate' => '采购交期回复', 'target' => 'Purchse Order Statistics', 'target_id' => $id, 'computer_name' => gethostbyaddr(getenv("REMOTE_ADDR")), 'ip' => $_SERVER['REMOTE_ADDR'], 'content' => $params, 'time' => $now);
             try {
                 $operate = new Application_Model_Log_Operate();
                 $operate->insert($data);
             } catch (Exception $e) {
                 $result['success'] = false;
                 $result['info'] = $e->getMessage();
                 echo Zend_Json::encode($result);
                 exit;
             }
         }
         $item->update($updateData, "id = " . $id);
     } else {
         $result['success'] = false;
         $result['info'] = '信息填写错误,交期回复失败!';
     }
     echo Zend_Json::encode($result);
     exit;
 }
Exemplo n.º 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;
    }