//Controller
class Product_ReceivingController extends Zend_Controller_Action {
//质检组收货及积压报表
public function qcGroupReceivingAndBacklogReportAction() {
set_time_limit(0);
$catearray = Product_Service_Receiving::$productCategory;
if ($this->_request->isPost()) {
$warehouseId = $this->_request->getParam("userWarehouse", "");
$startTime = $this->_request->getParam("start_time", "");
$endTime = $this->_request->getParam("end_time", "");
$return = array(
"ask" => 0,
"msg" => "",
"data" => "",
"count" => "",
);
if (!$warehouseId) {
$return['msg'] = "请选择仓库";
die(Zend_Json::encode($return));
}
if (!$startTime || !$endTime) {
$return['msg'] = "请选择时间";
die(Zend_Json::encode($return));
}
$list = array();
$week = array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
$date = date("Y-m-d");
if (strtotime($endTime) >= strtotime($date)) {
//收货数据
$combination = array(
"warehouse_id" => $warehouseId,
"rp_receiving_time_from" => $date . " 00:00:00",
"rp_receiving_time_to" => $date . " 23:59:59",
"asn_has" => "0",
);
$receivingIds = Product_Service_ReceivingPre::getByleftJoin($combination, "*", "rp_receiving_time desc");
if ($receivingIds) {
$row = array();
foreach ($receivingIds as $key => $value) {
if ($value['warehouse_id'] == 11) {
if ($value['ref_id'] != "") {
//用采购单做为键(客户参考号)
$key = $value['ref_id'];
$row[$key] = $value;
}
} else {
if ($value['receiving_code'] != "") {
//用 ASN 单号作为键
$key = $value['receiving_code'];
$row[$key] = $value;
}
}
}
foreach ($row as $ke => $valu) {
//用收货时间作为键
$rpReceivingTime = substr($valu['rp_receiving_time'], 0, 10);
$list[$rpReceivingTime]['count_po'][] = $ke;
$list[$rpReceivingTime]['qrb_po'] = count($list[$rpReceivingTime]['count_po']);
if ($valu['plat_form'] == "CSP") {
$list[$rpReceivingTime]['count_csp'][] = $ke;
$list[$rpReceivingTime]['qrb_csp'] = count($list[$rpReceivingTime]['count_csp']);
}
if (isset($list[$rpReceivingTime]['qrb_csp']) != 0 && $list[$rpReceivingTime]['qrb_po'] != 0) {
$list[$rpReceivingTime]['qrb_csp_proportion'] = round($list[$rpReceivingTime]['qrb_csp'] / $list[$rpReceivingTime]['qrb_po'], 4) * 100;
}
}
}
//未绑定 PO 票数
$combinat = array(
"warehouse_id" => $warehouseId,
"rp_receiving_time_from" => $date,
"rp_receiving_time_to_2" => $date . " 21:00:00",
"asn_has" => 1,
"rp_status" => "0",
);
$rpIds = Product_Service_ReceivingPre::getByCondition($combinat, "*", "rp_receiving_time desc");
if ($rpIds) {
foreach ($rpIds as $val) {
//用收货时间作为键
$rpReceivingTime = substr($val['rp_receiving_time'], 0, 10);
$list[$rpReceivingTime]['rp_tracking_number'][] = $val['rp_tracking_number'];
$list[$rpReceivingTime]['qrb_no_po'] = count(array_unique($list[$rpReceivingTime]['rp_tracking_number']));
}
}
//积压数据
$combin = array(
"warehouse_id" => $warehouseId,
"rp_receiving_time_from" => $date . " 00:00:00",
"rp_receiving_time_to" => $date . " 21:00:00",
"asn_has" => "0",
"rp_status" => "0",
);
$receivingIdInfo = Product_Service_ReceivingPre::getByleftJoin($combin, "*", "rp_receiving_time desc");
if ($receivingIdInfo) {
$arr = array();
foreach ($receivingIdInfo as $k => $va) {
if ($va['ref_id'] != "" && $va['customer_id'] == "STK01") {
//用采购单做为键(客户参考号)
$k = $va['ref_id'];
$arr[$k] = $va;
}
}
foreach ($arr as $ky => $vl) {
//用收货时间和品类作为键
$rpReceivingTime = substr($vl['rp_receiving_time'], 0, 10);
$category = $vl['category'];
if ($vl['plat_form'] == "CSP") {
$list[$rpReceivingTime]['count_is_csp'][] = $ky;
$list[$rpReceivingTime]['qrb_is_csp'] = count($list[$rpReceivingTime]['count_is_csp']);
} else {
$list[$rpReceivingTime]['count_no_csp'][] = $ky;
$list[$rpReceivingTime]['qrb_no_csp'] = count($list[$rpReceivingTime]['count_no_csp']);
}
if ($category != 0) {
if (!isset($list[$rpReceivingTime]['category'])) {
$catearray = Product_Service_Receiving::$productCategory;
foreach ($catearray as $kk => $v) {
$list[$rpReceivingTime]['category'][$kk] = 0;
}
}
$list[$rpReceivingTime]['category'][$category] += 1;
}
}
}
$comb = array(
"warehouse_id" => $warehouseId,
"start_date" => $startTime,
"end_date" => $endTime,
);
$qrbIds = Product_Service_QualityReceivingBacklog::getCombination($comb, "*", "qrb_date desc");
if ($qrbIds) {
foreach ($qrbIds as $kkk => $vv) {
$kkk = $vv['qrb_date'];
$list[$kkk] = $vv;
}
}
} else {
$comb = array(
"warehouse_id" => $warehouseId,
"start_date" => $startTime,
"end_date" => $endTime,
);
$qrbIds = Product_Service_QualityReceivingBacklog::getCombination($comb, "*", "qrb_date desc");
if ($qrbIds) {
foreach ($qrbIds as $kkk => $vv) {
$kkk = $vv['qrb_date'];
$list[$kkk] = $vv;
}
}
}
if (!$list) {
$return['msg'] = "未获取到对应数据";
die(json_encode($return));
}
foreach ($list as $kkkk => $vvv) {
!isset($vvv['qrb_category']) ? "" : $list[$kkkk]['category'] = unserialize($vvv['qrb_category']);
$list[$kkkk]['week'] = $week[date("w", strtotime($kkkk))];
$list[$kkkk]['qrb_po'] = !isset($list[$kkkk]['qrb_po']) ? "" : $list[$kkkk]['qrb_po'];
$list[$kkkk]['qrb_csp'] = !isset($list[$kkkk]['qrb_csp']) ? "" : $list[$kkkk]['qrb_csp'];
$list[$kkkk]['qrb_csp_proportion'] = !isset($list[$kkkk]['qrb_csp_proportion']) ? "" : $list[$kkkk]['qrb_csp_proportion'];
$list[$kkkk]['qrb_no_po'] = !isset($list[$kkkk]['qrb_no_po']) ? "" : $list[$kkkk]['qrb_no_po'];
$list[$kkkk]['qrb_no_csp'] = !isset($list[$kkkk]['qrb_no_csp']) ? "" : $list[$kkkk]['qrb_no_csp'];
$list[$kkkk]['qrb_is_csp'] = !isset($list[$kkkk]['qrb_is_csp']) ? "" : $list[$kkkk]['qrb_is_csp'];
$list[$kkkk]['qrb_category'] = !isset($list[$kkkk]['category']) ? "" : $list[$kkkk]['category'];
}
$return['ask'] = 1;
$return['data'] = $list;
$return['count'] = count($list);
$return['count_category'] = count($catearray);
die(Zend_Json::encode($return));
}
$this->view->category = $catearray;
echo Cff::renderTpl($this->tplDirectory . "receiving-and-backlog-reports.tpl", "layout");
}
}
//Service
class Product_Service_Receiving {
public static $productCategory = array(
"51" => "手机电子",
"52" => "汽摩配",
"53" => "家居装饰",
"54" => "运动",
"55" => "服装",
"56" => "珠宝",
"57" => "玩具",
"58" => "婚庆",
"59" => "手工",
"60" => "园艺",
"61" => "爱好",
"62" => "美妆",
"63" => "电脑电子",
"64" => "宠物灯饰",
"65" => "骑行渔具",
"66" => "户外",
"67" => "摩配",
"68" => "消费电子",
);
//Html
<!DOCTYPE html>
<html>
<head>
<title>质检组收货及积压报表</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="/css/order/transport.css" rel="stylesheet" type="text/css"/>
<script src="/js/product/receiving/receiving-and-backlog-reports.js"></script>
</head>
<body>
<div class="search_div">
<form id="sForm" name="sForm" onsubmit='return false;'>
<div>
<label>
<{include file=$userWarehouseTpl}>
</label>
<input type="text" name="start_time" id="start_time" style="text-align: center">
- -
<input type="text" name="end_time" id="end_time" style="text-align: center">
<input class="button search" type="button" value="搜索">
<input class="button" type="button" value="收件人" onclick="addressee()">
</div>
</form>
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="myTab">
<tbody>
<tr class="even-tr">
<th colspan="2">时间</th>
<th colspan="3">收货数据</th>
<th colspan="100%">积压数据</th>
</tr>
<tr class="even-tr">
<th rowspan="2">日期</th>
<th rowspan="2">星期</th>
<th rowspan="2">PO 收货量</th>
<th rowspan="2">CSP 收货量</th>
<th rowspan="2">CSP 占比</th>
<th rowspan="2">未绑定 PO 票数</th>
<th colspan="2">合计</th>
<{foreach from=$category key="key" item="value"}>
<th rowspan="2" value="<{$key}>"><{$value}></th>
<{/foreach}>
</tr>
<tr class="even-tr">
<th>非 CSP</th>
<th>CSP</th>
</tr>
</tbody>
<tbody id="loadData" style="text-align: center"></tbody>
</table>
<div id="addresseeDialog" title="收件人" style="display: none; text-align:center"></div>
</body>
</html>
//Js
//初始化
$(function () {
//日期
var dayNamesMin = ["日", "一", "二", "三", "四", "五", "六"];
var monthNamesShort = ["01月", "02月", "03月", "04月", "05月", "06月", "07月", "08月", "09月", "10月", "11月", "12月"];
$("#start_time").datepicker({
dayNamesMin: dayNamesMin,
monthNamesShort: monthNamesShort,
changeMonth: true,
changeYear: true,
dateFormat: "yy-mm-dd"
});
$("#end_time").datepicker({
dayNamesMin: dayNamesMin,
monthNamesShort: monthNamesShort,
changeMonth: true,
changeYear: true,
dateFormat: "yy-mm-dd"
});
//搜索
$(".search").click(function () {
initData(0);
});
});
//列表
function loadData() {
loading();
$.ajax({
url: "/product/receiving/qc-group-receiving-and-backlog-report",
async: false,
dataType: "json",
type: "post",
data: $("#sForm").serializeArray(),
success: function (json) {
var Html = "";
if (!json.ask) {
alertTip(json.msg);
Html += "<tr><td colspan='100%'>" + json.msg + "</td></tr>";
} else {
$.each(json.data, function (key, value) {
Html += "<tr>";
Html += "<td>" + key + "</td>";
Html += "<td>" + value.week + "</td>";
Html += "<td>" + value.qrb_po + "</td>";
Html += "<td>" + value.qrb_csp + "</td>";
Html += "<td>" + value.qrb_csp_proportion + "%</td>";
Html += "<td>" + value.qrb_no_po + "</td>";
Html += "<td>" + value.qrb_no_csp + "</td>";
Html += "<td>" + value.qrb_is_csp + "</td>";
if (value.qrb_category) {
$.each(value.qrb_category, function (k, val) {
if (val != 0) {
Html += "<td value=" + k + ">" + val + "</td>";
} else {
Html += "<td value=" + k + "></td>";
}
})
} else {
for (var i = 0; i < json.count_category; i++) {
Html += "<td></td>";
}
}
Html += "</tr>";
});
}
$("#loadData").html(Html);
}
});
closeLoading();
}
//提示
function alertTip(tip) {
$("<div title='提示'><p align='center'>" + tip + "</p></div>").dialog({
modal: true,
buttons: {
'确定': function () {
$(this).dialog("close");
}
}
});
}
实时数据优化
最新推荐文章于 2021-09-07 17:05:46 发布