tp6框架的销售统计系统

input.html 25KB

    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog" style="width:800px"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" aria-hidden="true" onclick="cel()"> &times; </button> <button type="button" class="btn btn-default btn-sm" aria-hidden="true" onclick="updatecahce()" style="float:right;margin-right: 30px;"> 刷新销售数据 </button> <h4 class="modal-title" id="myModalLabel"> 数据录入 </h4> </div> <div class="modal-body"> <form role="form" id="market-form"> <input type="hidden" name="id" id="id" value="0"> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="name">计提月份</label> <select name="month" id="month" class="form-control"> <?php foreach ($maonth_picker->monarr as $value) { if ($maonth_picker->cur_month == $value) { echo "<option value='$value' selected>$value</option>"; } else { echo "<option value='$value'>$value</option>"; } } ?> </select> </div> </div> <div class="col-md-6"> <div class="form-group"> <label for="name">公司名称</label> <select class="selectpicker form-control" data-live-search="true" name="company" id="company"> <option value="">公司名称</option> <?php foreach ($data_company as $company) { ?> <option value="<?php echo $company['name'] ?>"><?php echo $company['name'] ?></option> <?php } ?> </select> </div> </div> </div> <div class="row"> <div class="col-md-12"> <div class="form-group"> <label for="name">请选择要录入的数据</label> <select class="form-control" name="conpany_sales_data" id="conpany_sales_data"> <option value="0">请选择合同数据</option> </select> </div> </div> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="name">合同号</label> <input type="text" class="form-control" name="contract_no" id="contract_no" placeholder="合同号"> </div> </div> <div class="col-md-6"> <div class="form-group"> <label for="name">产品类别</label> <input type="text" class="form-control" name="goods_category" id="goods_category" placeholder="产品类别"> </div> </div> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="name">产品型号</label> <input type="text" class="form-control" name="goods_type" id="goods_type" placeholder="产品型号"> </div> </div> <div class="col-md-6"> <div class="form-group"> <label for="name">数量(KG)</label> <input type="number" class="form-control val_change" name="amount" id="amount" placeholder="数量"> </div> </div> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="name">单价</label> <input type="number" class="form-control val_change" name="price" id="price" placeholder="单价"> </div> </div> <div class="col-md-6"> <div class="form-group"> <label for="name">合同额</label> <input type="number" class="form-control val_change" name="contract_value" id="contract_value" placeholder="合同额"> </div> </div> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="name">代理费</label> <input type="number" class="form-control val_change" name="agency" id="agency" placeholder="代理费"> </div> </div> <div class="col-md-6"> <div class="form-group"> <label for="name">运费</label> <input type="number" class="form-control val_change" name="shipping" id="shipping" placeholder="运费"> </div> </div> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="name">收款金额</label> <input type="number" class="form-control val_change" name="receive_money" id="receive_money" placeholder="收款金额"> </div> </div> <div class="col-md-6"> <div class="form-group"> <label for="name">上期余额</label> <input type="number" class="form-control" name="period_balance" id="period_balance" placeholder="上期余额"> </div> </div> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="name">实收金额</label> <input type="number" class="form-control" name="actual_money" id="actual_money" placeholder="实收金额"> </div> </div> <div class="col-md-6"> <div class="form-group"> <label for="name">本期结余</label> <input type="number" class="form-control" name="current_balance" id="current_balance" placeholder="本期结余"> </div> </div> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="name">提成类型</label> <label class="radio-inline"> <input type="radio" name="type" id="type0" value="0" checked="checked" onclick="tcType(0)"> 一般 </label> <label class="radio-inline"> <input type="radio" name="type" id="type1" value="1" onclick="tcType(1)"> 特批1 </label> <label class="radio-inline"> <input type="radio" name="type" id="type2" value="2" onclick="tcType(2)"> 特批2 </label> </div> </div> </div> <div id="yiban" class="active bj"> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="name">基准单价</label> <input type="number" class="form-control val_change" name="base_price" id="base_price" placeholder="基准单价"> </div> </div> <div class="col-md-6"> <div class="form-group"> <label for="name">合同基准价</label> <input type="number" class="form-control" name="base_value" id="base_value" placeholder="合同基准价"> </div> </div> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="name">工程费成本</label> <input type="number" class="form-control val_change" name="project" id="project" placeholder="工程费成本"> </div> </div> <div class="col-md-6"> <div class="form-group"> <label for="name">总利润</label> <input type="number" class="form-control" name="total_profit" id="total_profit" placeholder="总利润"> </div> </div> </div> </div> <div id="tepi" class="bj"> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="name">公司低价</label> <input type="number" class="form-control val_change" name="base_price2" id="base_price2" placeholder="基准单价"> </div> </div> <div class="col-md-6"> <div class="form-group"> <label for="name">实际合同额</label> <input type="number" class="form-control" name="actual_value" id="actual_value" placeholder="实际合同额"> </div> </div> </div> <div class="row"> <div class="col-md-4"> <div class="form-group"> <label for="name">价格比例</label> <input type="number" class="form-control" name="price_rate" id="price_rate" placeholder="价格比例"> </div> </div> <div class="col-md-4"> <div class="form-group"> <label for="name">提成比例</label> <input type="number" class="form-control" name="commission_rate" id="commission_rate" placeholder="提成比例"> </div> </div> <div class="col-md-4"> <div class="form-group"> <label for="name">提成额</label> <input type="number" class="form-control" name="commission_money" id="commission_money" placeholder="提成额"> </div> </div> </div> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="name">销售员</label> <input type="text" class="form-control" name="seller" id="seller" placeholder="销售员"> </div> </div> <div class="col-md-6"> <div class="form-group"> <label for="name">备注</label> <input type="text" class="form-control" name="remark" id="remark" placeholder="备注"> </div> </div> </div> <div class="row"> </div> </form> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" onclick="cel()">关闭 </button> <button type="button" class="btn btn-primary" onclick="doSave()"> 提交 </button> </div> </div><!-- /.modal-content --> </div><!-- /.modal --> </div> <script> function edit(id) { $.ajax({ url: "/index/commission/info/id/"+id, type: "GET", data: {}, dataType: 'json', success: function(res) { if (res.code == 0) { dataForm = res.data; // console.log(dataForm); // return false; $("#id").val(dataForm.id); $('#company').selectpicker('val', dataForm.company); getContractNoByCompany(dataForm.company, dataForm.former_id); $("#contract_no").val(dataForm.contract_no); $("#goods_category").val(dataForm.goods_category); $("#goods_type").val(dataForm.goods_type); $("#amount").val(dataForm.amount); $("#price").val(dataForm.price); $("#contract_value").val(dataForm.contract_value); $("#receive_money").val(dataForm.receive_money); $("#period_balance").val(dataForm.period_balance); $("#actual_money").val(dataForm.actual_money); $("#agency").val(dataForm.agency); $("#shipping").val(dataForm.shipping); $("#current_balance").val(dataForm.current_balance); let type = dataForm.type; // console.log(type) $('input[name="type"]').prop('checked', false); $("#type" + type).prop('checked', true); if (type != 0) { $("#base_price2").val(dataForm.base_price); $("#actual_value").val(dataForm.actual_value); $("#price_rate").val(dataForm.price_rate); $("#commission_rate").val(dataForm.c_rate); $("#commission_money").val(dataForm.c_money); $('#yiban').removeClass('active'); $('#tepi').addClass('active'); } else { $("#base_price").val(dataForm.base_price); $("#base_value").val(dataForm.base_value); $("#project").val(dataForm.project); $("#total_profit").val(dataForm.total_profit); $('#tepi').removeClass('active'); $('#yiban').addClass('active'); } $("#seller").val(dataForm.seller); $("#remark").val(dataForm.remark); $('#myModal').modal('show'); return false; } else { alert(res.msg); } return false; } }); } var dataForm = { "id": 0, "month": "", "company": "", "contract_no": "", "goods_category": "", "goods_type": "", "amount": 0, "price": 0, "contract_value": 0, "receive_money": 0, "period_balance": 0, "agency": 0, "base_price": 0, "shipping": 0, "project": 0, "type": 0, "seller": "", "remark": "", "former_id": 0 }; // 销售数据 var salesData = getSalesData() // console.log(salesData) // 公司名称下的合同数据 var conpanySalesData = []; // (从缓存读取) function getSalesData() { salesData = JSON.parse(window.localStorage.getItem('salesData')); return salesData; } // 根据公司名选择数据条 function getContractNoByCompany(company, former_id=0) { conpanySalesData = []; // 清空数组 var option = {}; let str = '<option value="0">请选择合同数据</option>'; var key=1; for (var i=1; i < salesData.length; i++) { row = salesData[i]; // console.log(row); if (row[3] == company) { option.contract_no = row[12]; option.goods_category = row[6]; option.goods_type = row[7]; option.amount = row[8]; option.price = row[10]; option.contract_value = row[11]; option.seller = row[13]; option.shipping = row[15]; option.former_id = row[16]; conpanySalesData[key] = option; if (option.former_id == former_id) { str += '<option value="' + key + '" selected>'+ row[1] +','+ option.contract_no +','+option.goods_category+','+ option.goods_type+','+ option.amount+','+ option.price+','+ option.contract_value+'</option>'; } else { str += '<option value="' + key + '">'+ row[1] +','+ option.contract_no +','+option.goods_category+','+ option.goods_type+','+ option.amount+','+ option.price+','+ option.contract_value+'</option>'; } key++; option = {}; } } $('#conpany_sales_data').html(str); } // update 上期结余 function updatePeriodBalance() { $.post('/index/commission/perbalance', { 'company': dataForm.company }, function(res) { // console.log(res); if (res.code == 0) { dataForm.period_balance = res.data; $("#period_balance").val(dataForm.period_balance) } }, 'json') } $("#company").change(function() { dataForm.company = $(this).val(); getContractNoByCompany(dataForm.company); updatePeriodBalance(); }) $('#conpany_sales_data').change(function(){ // 销售表读取的数据 var k = $('#conpany_sales_data').val(); // console.log(k); if (k==0) { $("#market-form")[0].reset(); } else { var data = conpanySalesData[k]; console.log(data); dataForm.contract_no = data.contract_no; dataForm.goods_category = data.goods_category; dataForm.goods_type = data.goods_type; dataForm.amount = data.amount; if (data.price.indexOf('(') != -1) { var price = ltrim(data.price, '('); price = rtrim(price, ')'); dataForm.price = Number(-price); } else { dataForm.price = data.price; } dataForm.seller = data.seller; dataForm.shipping = data.shipping; dataForm.former_id = data.former_id; if (data.contract_value.indexOf('(') != -1) { var contract_value = ltrim(data.contract_value, '('); contract_value = rtrim(contract_value, ')'); dataForm.contract_value = Number(-contract_value); } else { dataForm.contract_value = Number(data.contract_value); } $("#contract_no").val(dataForm.contract_no); $("#goods_category").val(dataForm.goods_category); $("#goods_type").val(dataForm.goods_type); $("#amount").val(Number(dataForm.amount)); if (dataForm.price<0) { $("#price").css('color', 'red'); } $("#price").val(Number(dataForm.price)); if (dataForm.contract_value<0) { $("#contract_value").css('color', 'red'); } $("#contract_value").val(dataForm.contract_value); $("#seller").val(dataForm.seller); $("#shipping").val(Number(dataForm.shipping)); $("#agency").val(0); $("#receive_money").val(0); $("#actual_money").val(0); $("#current_balance").val(0); $("#project").val(0); } }) // 更新dataFrom function updateDataFrom() { dataForm.shipping = Number($("#shipping").val()); dataForm.contract_value = Number($("#contract_value").val()); dataForm.agency = Number($("#agency").val()); // 更新实收金额 var receive_money = Number($("#receive_money").val()); dataForm.receive_money = receive_money; dataForm.actual_money = receive_money + dataForm.period_balance; $("#actual_money").val(dataForm.actual_money) ; // 本期结余 dataForm.current_balance = dataForm.actual_money - dataForm.contract_value; $("#current_balance").val(dataForm.current_balance); } $(".val_change").change(function() { updateDataFrom(); updateBaseValue(); updateTotalProfit(); updateTepi(); }) function tcType(bj) { dataForm.type = bj; if (bj != 0) { $('#yiban').removeClass('active'); $('#tepi').addClass('active'); } else { $('#tepi').removeClass('active'); $('#yiban').addClass('active'); } } // 合同基准价 function updateBaseValue() { var amount = $("#amount").val(); var base_price = $("#base_price").val(); $("#base_value").val(amount * base_price); } // 总利润 function updateTotalProfit() { var contract_value = Number($("#contract_value").val()); var agency = Number($("#agency").val()); var base_value = Number($("#base_value").val()); var shipping = Number($("#shipping").val()); var total_profit = contract_value - agency - base_value - shipping; $("#total_profit").val(total_profit); } //价格比例 & 提成比例 特批 function updateTepi() { var base_price = Number($("#base_price2").val()); if (dataForm.type != 0) { dataForm.base_price = base_price; var price = $("#price").val(); var price_rate = price / base_price; $("#price_rate").val(price_rate); var contract_value = Number($("#contract_value").val()); var agency = Number($("#agency").val()); var actual_value = contract_value - agency; $("#actual_value").val(actual_value); var shipping = Number($("#shipping").val()); if (dataForm.type == 1) { if (price_rate < 1.05) { dataForm.commission_rate = 0.01; } else if (price_rate < 1.1) { dataForm.commission_rate = 0.015; } else { dataForm.commission_rate = 0.02; } } else { dataForm.commission_rate = Math.floor((((price_rate - 1) / 0.1) * 0.01 + 0.01) * 100) / 100; // console.log(dataForm.commission_rate) } $("#commission_rate").val(dataForm.commission_rate); var commission_money = ((actual_value - shipping) * dataForm.commission_rate).toFixed(2); $("#commission_money").val(commission_money); } } function doSave() { dataForm.id = $('#id').val(); dataForm.month = $('#month').val(); dataForm.type = $('input[name="type"]:checked').val(); if (dataForm.type != 0) { dataForm.base_price = Number($('#base_price2').val()); } else { dataForm.base_price = Number($('#base_price').val()); } dataForm.remark = $('#remark').val(); $.ajax({ url: "/index/commission/save", type: "POST", data: dataForm, dataType: 'json', success: function(res) { if (res.code == 0) { alert('保存成功'); window.location.reload(); } else { alert(res.msg); } return false; } }); } function updatecahce() { storageSalesData(true); } function cel() { dataForm.id = 0; $('#id').val(0); $('#company').selectpicker('val', ''); $('#conpany_sales_data').html(''); $('#myModal').modal('hide'); $("#market-form")[0].reset(); } </script>