//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();
for ($i = strtotime($startTime); $i <= strtotime($endTime); $i+=86400) {
$date = date("Y-m-d", $i);
//收货数据
$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'][] = $ke;
$list[$rpReceivingTime]['count_po'] = count($list[$rpReceivingTime]['count']);
if ($valu['plat_form'] == "CSP") {
$list[$rpReceivingTime]['csp'][] = $ke;
$list[$rpReceivingTime]['count_csp'] = count($list[$rpReceivingTime]['csp']);
}
if (isset($list[$rpReceivingTime]['count_csp']) != 0 && $list[$rpReceivingTime]['count_po'] != 0) {
$list[$rpReceivingTime]['csp_proportion'] = round($list[$rpReceivingTime]['count_csp'] / $list[$rpReceivingTime]['count_po'], 4) * 100 . "%";
}
}
}
//未绑定 PO 票数
$combinat = array(
"warehouse_id" => $warehouseId,
"rp_receiving_time_from" => $date,
"rp_receiving_time_to" => $date,
"asn_has" => 1,
);
$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]['in_po'] = count(array_unique($list[$rpReceivingTime]['rp_tracking_number']));
}
}
//积压数据
$comb = 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($comb, "*", "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]['totUpCsp'][] = $ky;
$list[$rpReceivingTime]['tot_up_csp'] = count($list[$rpReceivingTime]['totUpCsp']);
} else {
$list[$rpReceivingTime]['totUp'][] = $ky;
$list[$rpReceivingTime]['tot_up'] = count($list[$rpReceivingTime]['totUp']);
}
if ($category != 0) {
if (!isset($list[$rpReceivingTime]['category'])) {
foreach ($catearray as $kk => $v) {
$list[$rpReceivingTime]['category'][$kk] = 0;
}
}
$list[$rpReceivingTime]['category'][$category] += 1;
}
}
}
}
if (!$list) {
$return['msg'] = "未查询到对应数据";
die(Zend_Json::encode($return));
}
$week = array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
foreach ($list as $kkk => $vv) {
$list[$kkk]['week'] = $week[date("w", strtotime($kkk))];
$list[$kkk]['count_po'] = !isset($list[$kkk]['count_po']) ? "" : $list[$kkk]['count_po'];
$list[$kkk]['count_csp'] = !isset($list[$kkk]['count_csp']) ? "" : $list[$kkk]['count_csp'];
$list[$kkk]['csp_proportion'] = !isset($list[$kkk]['csp_proportion']) ? "" : $list[$kkk]['csp_proportion'];
$list[$kkk]['in_po'] = !isset($list[$kkk]['in_po']) ? "" : $list[$kkk]['in_po'];
$list[$kkk]['tot_up'] = !isset($list[$kkk]['tot_up']) ? "" : $list[$kkk]['tot_up'];
$list[$kkk]['tot_up_csp'] = !isset($list[$kkk]['tot_up_csp']) ? "" : $list[$kkk]['tot_up_csp'];
$list[$kkk]['category'] = !isset($list[$kkk]['category']) ? 0 : $list[$kkk]['category'];
}
krsort($list);
$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="搜索">
</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="4">收货数据</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>
</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.count_po + "</td>";
Html += "<td>" + value.count_csp + "</td>";
Html += "<td>" + value.csp_proportion + "</td>";
Html += "<td>" + value.in_po + "</td>";
Html += "<td>" + value.tot_up + "</td>";
Html += "<td>" + value.tot_up_csp + "</td>";
if (value.category != 0) {
$.each(value.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");
}
}
});
}
实时数据
最新推荐文章于 2024-06-18 13:43:55 发布