赛亿提成统计系统

input.php 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  2. <div class="modal-dialog" style="width:800px">
  3. <div class="modal-content">
  4. <div class="modal-header">
  5. <button type="button" class="close" aria-hidden="true" onclick="cel()">
  6. &times;
  7. </button>
  8. <button type="button" class="btn btn-default btn-sm" aria-hidden="true" onclick="updatecahce()" style="float:right;margin-right: 30px;">
  9. 刷新
  10. </button>
  11. <h4 class="modal-title" id="myModalLabel">
  12. 数据录入
  13. </h4>
  14. </div>
  15. <div class="modal-body">
  16. <form role="form" id="market-form">
  17. <input type="hidden" name="id" id="id" value="0">
  18. <div class="row">
  19. <div class="col-md-6">
  20. <div class="form-group">
  21. <label for="name">计提月份</label>
  22. <select name="month" id="month" class="form-control">
  23. <?php
  24. foreach ($maonth_picker->monarr as $value) {
  25. if ($maonth_picker->cur_month == $value) {
  26. echo "<option value='$value' selected>$value</option>";
  27. } else {
  28. echo "<option value='$value'>$value</option>";
  29. }
  30. }
  31. ?>
  32. </select>
  33. </div>
  34. </div>
  35. <div class="col-md-6">
  36. <div class="form-group">
  37. <label for="name">公司名称</label>
  38. <select class="selectpicker form-control" data-live-search="true" name="company" id="company">
  39. <option value="">公司名称</option>
  40. <?php
  41. foreach ($data_company as $company) {
  42. ?>
  43. <option value="<?php echo $company['name'] ?>"><?php echo $company['name'] ?></option>
  44. <?php
  45. }
  46. ?>
  47. </select>
  48. </div>
  49. </div>
  50. </div>
  51. <div class="row">
  52. <div class="col-md-12">
  53. <div class="form-group">
  54. <label for="name">请选择要录入的数据</label>
  55. <select class="form-control" name="conpany_sales_data" id="conpany_sales_data">
  56. <option value="">请选择合同号</option>
  57. </select>
  58. </div>
  59. </div>
  60. </div>
  61. <div class="row">
  62. <div class="col-md-6">
  63. <div class="form-group">
  64. <label for="name">合同号</label>
  65. <input type="text" class="form-control" name="contract_no" id="contract_no" placeholder="合同号">
  66. </div>
  67. </div>
  68. <div class="col-md-6">
  69. <div class="form-group">
  70. <label for="name">产品类别</label>
  71. <input type="text" class="form-control" name="goods_category" id="goods_category" placeholder="产品类别">
  72. </div>
  73. </div>
  74. </div>
  75. <div class="row">
  76. <div class="col-md-6">
  77. <div class="form-group">
  78. <label for="name">产品型号</label>
  79. <input type="text" class="form-control" name="goods_type" id="goods_type" placeholder="产品型号">
  80. </div>
  81. </div>
  82. <div class="col-md-6">
  83. <div class="form-group">
  84. <label for="name">数量(KG)</label>
  85. <input type="number" class="form-control val_change" name="amount" id="amount" placeholder="数量">
  86. </div>
  87. </div>
  88. </div>
  89. <div class="row">
  90. <div class="col-md-6">
  91. <div class="form-group">
  92. <label for="name">单价</label>
  93. <input type="number" class="form-control val_change" name="price" id="price" placeholder="单价">
  94. </div>
  95. </div>
  96. <div class="col-md-6">
  97. <div class="form-group">
  98. <label for="name">合同额</label>
  99. <input type="number" class="form-control" name="contract_value" id="contract_value" placeholder="合同额">
  100. </div>
  101. </div>
  102. </div>
  103. <div class="row">
  104. <div class="col-md-6">
  105. <div class="form-group">
  106. <label for="name">代理费</label>
  107. <input type="number" class="form-control val_change" name="agency" id="agency" placeholder="代理费">
  108. </div>
  109. </div>
  110. <div class="col-md-6">
  111. <div class="form-group">
  112. <label for="name">运费</label>
  113. <input type="number" class="form-control val_change" name="shipping" id="shipping" placeholder="运费">
  114. </div>
  115. </div>
  116. </div>
  117. <div class="row">
  118. <div class="col-md-6">
  119. <div class="form-group">
  120. <label for="name">收款金额</label>
  121. <input type="number" class="form-control val_change" name="receive_money" id="receive_money" placeholder="收款金额">
  122. </div>
  123. </div>
  124. <div class="col-md-6">
  125. <div class="form-group">
  126. <label for="name">上期余额</label>
  127. <input type="number" class="form-control" name="period_balance" id="period_balance" placeholder="上期余额" disabled>
  128. </div>
  129. </div>
  130. </div>
  131. <div class="row">
  132. <div class="col-md-6">
  133. <div class="form-group">
  134. <label for="name">实收金额</label>
  135. <input type="number" class="form-control" name="actual_money" id="actual_money" placeholder="实收金额" disabled="true">
  136. </div>
  137. </div>
  138. <div class="col-md-6">
  139. <div class="form-group">
  140. <label for="name">本期结余</label>
  141. <input type="number" class="form-control" name="current_balance" id="current_balance" placeholder="本期结余" disabled="true">
  142. </div>
  143. </div>
  144. </div>
  145. <div class="row">
  146. <div class="col-md-6">
  147. <div class="form-group">
  148. <label for="name">提成类型</label>
  149. <label class="radio-inline">
  150. <input type="radio" name="type" id="type0" value="0" checked="checked" onclick="tcType(0)"> 一般
  151. </label>
  152. <label class="radio-inline">
  153. <input type="radio" name="type" id="type1" value="1" onclick="tcType(1)"> 特批1
  154. </label>
  155. <label class="radio-inline">
  156. <input type="radio" name="type" id="type2" value="2" onclick="tcType(2)"> 特批2
  157. </label>
  158. </div>
  159. </div>
  160. </div>
  161. <div id="yiban" class="active bj">
  162. <div class="row">
  163. <div class="col-md-6">
  164. <div class="form-group">
  165. <label for="name">基准单价</label>
  166. <input type="number" class="form-control val_change" name="base_price" id="base_price" placeholder="基准单价">
  167. </div>
  168. </div>
  169. <div class="col-md-6">
  170. <div class="form-group">
  171. <label for="name">合同基准价</label>
  172. <input type="number" class="form-control" name="base_value" id="base_value" placeholder="合同基准价" disabled="true">
  173. </div>
  174. </div>
  175. </div>
  176. <div class="row">
  177. <div class="col-md-6">
  178. <div class="form-group">
  179. <label for="name">工程费成本</label>
  180. <input type="number" class="form-control val_change" name="project" id="project" placeholder="工程费成本">
  181. </div>
  182. </div>
  183. <div class="col-md-6">
  184. <div class="form-group">
  185. <label for="name">总利润</label>
  186. <input type="number" class="form-control" name="total_profit" id="total_profit" placeholder="总利润" disabled="true">
  187. </div>
  188. </div>
  189. </div>
  190. </div>
  191. <div id="tepi" class="bj">
  192. <div class="row">
  193. <div class="col-md-6">
  194. <div class="form-group">
  195. <label for="name">公司低价</label>
  196. <input type="number" class="form-control val_change" name="base_price2" id="base_price2" placeholder="基准单价">
  197. </div>
  198. </div>
  199. <div class="col-md-6">
  200. <div class="form-group">
  201. <label for="name">实际合同额</label>
  202. <input type="number" class="form-control" name="actual_value" id="actual_value" placeholder="实际合同额">
  203. </div>
  204. </div>
  205. </div>
  206. <div class="row">
  207. <div class="col-md-4">
  208. <div class="form-group">
  209. <label for="name">价格比例</label>
  210. <input type="number" class="form-control" name="price_rate" id="price_rate" placeholder="价格比例" disabled="true">
  211. </div>
  212. </div>
  213. <div class="col-md-4">
  214. <div class="form-group">
  215. <label for="name">提成比例</label>
  216. <input type="number" class="form-control" name="commission_rate" id="commission_rate" placeholder="提成比例" disabled="true">
  217. </div>
  218. </div>
  219. <div class="col-md-4">
  220. <div class="form-group">
  221. <label for="name">提成额</label>
  222. <input type="number" class="form-control" name="commission_money" id="commission_money" placeholder="提成额" disabled="true">
  223. </div>
  224. </div>
  225. </div>
  226. </div>
  227. <div class="row">
  228. <div class="col-md-6">
  229. <div class="form-group">
  230. <label for="name">销售员</label>
  231. <input type="text" class="form-control" name="seller" id="seller" placeholder="销售员">
  232. </div>
  233. </div>
  234. <div class="col-md-6">
  235. <div class="form-group">
  236. <label for="name">备注</label>
  237. <input type="text" class="form-control" name="remark" id="remark" placeholder="备注">
  238. </div>
  239. </div>
  240. </div>
  241. <div class="row">
  242. </div>
  243. </form>
  244. </div>
  245. <div class="modal-footer">
  246. <button type="button" class="btn btn-default" onclick="cel()">关闭
  247. </button>
  248. <button type="button" class="btn btn-primary" id="tj">
  249. 提交
  250. </button>
  251. </div>
  252. </div><!-- /.modal-content -->
  253. </div><!-- /.modal -->
  254. </div>
  255. <script>
  256. var dataForm = {
  257. "id": 0,
  258. "month": "",
  259. "company": "",
  260. "contract_no": "",
  261. "goods_category": "",
  262. "goods_type": "",
  263. "amount": 0,
  264. "price": 0,
  265. "contract_value": 0,
  266. "receive_money": 0,
  267. "period_balance": 0,
  268. "agency": 0,
  269. "base_price": 0,
  270. "shipping": 0,
  271. "project": 0,
  272. "type": 0,
  273. "seller": "",
  274. "remark": ""
  275. };
  276. // 销售数据
  277. var salesData = getSalesData()
  278. // console.log(salesData)
  279. // 公司名称下的合同数据
  280. var conpanySalesData = [];
  281. // (从缓存读取)
  282. function getSalesData() {
  283. salesData = JSON.parse(window.localStorage.getItem('salesData'));
  284. return salesData;
  285. }
  286. // 根据公司名选择数据条
  287. function getContractNoByCompany(company) {
  288. conpanySalesData = []; // 清空数组
  289. var option = {};
  290. for (i=1; i < salesData.length; i++) {
  291. row = salesData[i];
  292. if (row[3] == company) {
  293. option.contract_no = row[12];
  294. option.goods_category = row[6];
  295. option.goods_type = row[7];
  296. option.amount = row[8];
  297. option.price = row[10];
  298. option.contract_value = row[11];
  299. option.seller = row[13];
  300. option.shipping = row[15];
  301. conpanySalesData.push(option);
  302. option = {};
  303. }
  304. }
  305. }
  306. // 更新公司下的数据list
  307. function updateCompanySalesData() {
  308. let str = '<option value="">请选择合同数据</option>';
  309. conpanySalesData.forEach((e, i) => {
  310. // console.log(e);
  311. str += '<option value="' + i + '">' + e.contract_no +','+e.goods_category+','+ e.goods_type+','+ e.amount+','+ e.price+','+ e.contract_value+'</option>';
  312. });
  313. $('#conpany_sales_data').html(str)
  314. }
  315. // update 上期结余
  316. function updatePeriodBalance() {
  317. $.post('/index/commission/perbalance', {
  318. 'company': dataForm.company
  319. }, function(res) {
  320. if (res.code == 0) {
  321. dataForm.period_balance = res.data;
  322. $("#period_balance").val(dataForm.period_balance)
  323. }
  324. }, 'json')
  325. }
  326. $("#company").change(function() {
  327. dataForm.company = $(this).val();
  328. getContractNoByCompany(dataForm.company);
  329. updateCompanySalesData();
  330. updatePeriodBalance();
  331. })
  332. $('#conpany_sales_data').change(function(){
  333. // 销售表读取的数据
  334. var i = $('#conpany_sales_data').val();
  335. var data = conpanySalesData[i];
  336. dataForm.contract_no = data.contract_no;
  337. dataForm.goods_category = data.goods_category;
  338. dataForm.goods_type = data.goods_type;
  339. dataForm.amount = data.amount;
  340. dataForm.price = data.price;
  341. dataForm.seller = data.seller;
  342. dataForm.shipping = data.shipping;
  343. if (data.contract_value.indexOf('(') != -1) {
  344. var contract_value = ltrim(data.contract_value, '(');
  345. contract_value = rtrim(contract_value, ')');
  346. dataForm.contract_value = Number(-contract_value);
  347. } else {
  348. dataForm.contract_value = Number(data.contract_value);
  349. }
  350. $("#contract_no").val(dataForm.contract_no)
  351. $("#goods_category").val(dataForm.goods_category)
  352. $("#goods_type").val(dataForm.goods_type)
  353. $("#amount").val(Number(dataForm.amount))
  354. $("#price").val(Number(dataForm.price))
  355. if (dataForm.contract_value<0) {
  356. $("#contract_value").css('color', 'red');
  357. }
  358. $("#contract_value").val(dataForm.contract_value);
  359. $("#seller").val(dataForm.seller)
  360. $("#shipping").val(Number(dataForm.shipping))
  361. })
  362. // 更新dataFrom
  363. function updateDataFrom() {
  364. dataForm.shipping = Number($("#shipping").val());
  365. // 更新实收金额
  366. var receive_money = Number($("#receive_money").val());
  367. dataForm.receive_money = receive_money;
  368. dataForm.actual_money = receive_money + dataForm.period_balance;
  369. $("#actual_money").val(dataForm.actual_money) ;
  370. // 本期结余
  371. dataForm.current_balance = dataForm.actual_money - dataForm.contract_value;
  372. $("#current_balance").val(dataForm.current_balance);
  373. }
  374. $(".val_change").change(function() {
  375. updateDataFrom();
  376. updateBaseValue();
  377. updateTotalProfit();
  378. updateTepi();
  379. })
  380. // 合同基准价
  381. function updateBaseValue() {
  382. var amount = $("#amount").val();
  383. var base_price = $("#base_price").val();
  384. $("#base_value").val(amount * base_price);
  385. }
  386. // 总利润
  387. function updateTotalProfit() {
  388. var contract_value = Number($("#contract_value").val());
  389. var agency = Number($("#agency").val());
  390. var base_value = Number($("#base_value").val());
  391. var shipping = Number($("#shipping").val());
  392. var total_profit = contract_value - agency - base_value - shipping;
  393. $("#total_profit").val(total_profit);
  394. }
  395. //价格比例 & 提成比例 特批
  396. function updateTepi() {
  397. var base_price = Number($("#base_price2").val());
  398. if (dataForm.type != 0) {
  399. dataForm.base_price = base_price;
  400. var price = $("#price").val();
  401. var price_rate = price / base_price;
  402. $("#price_rate").val(price_rate);
  403. var contract_value = Number($("#contract_value").val());
  404. var agency = Number($("#agency").val());
  405. var actual_value = contract_value - agency;
  406. $("#actual_value").val(actual_value);
  407. var shipping = Number($("#shipping").val());
  408. if (dataForm.type == 1) {
  409. if (price_rate < 1.05) {
  410. dataForm.commission_rate = 0.01;
  411. } else if (price_rate < 1.1) {
  412. dataForm.commission_rate = 0.015;
  413. } else {
  414. dataForm.commission_rate = 0.02;
  415. }
  416. } else {
  417. dataForm.commission_rate = Math.floor((((price_rate - 1) / 0.1) * 0.01 + 0.01) * 100) / 100;
  418. // console.log(dataForm.commission_rate)
  419. }
  420. $("#commission_rate").val(dataForm.commission_rate);
  421. var commission_money = ((actual_value - shipping) * dataForm.commission_rate).toFixed(2);
  422. $("#commission_money").val(commission_money);
  423. }
  424. }
  425. function tcType(bj) {
  426. dataForm.type = bj;
  427. if (bj != 0) {
  428. $('#yiban').removeClass('active');
  429. $('#tepi').addClass('active');
  430. } else {
  431. $('#tepi').removeClass('active');
  432. $('#yiban').addClass('active');
  433. }
  434. }
  435. function updatecahce() {
  436. window.location.href = "/index/index/index";
  437. }
  438. function cel() {
  439. $('#myModal').modal('hide');
  440. $("#market-form")[0].reset();
  441. $('#company').selectpicker('deselectAll');
  442. }
  443. $("#tj").click(function() {
  444. // dataForm.id = $("#id").val();
  445. // dataForm.month = $("#month").val();
  446. // dataForm.company = $("#company").val();
  447. // dataForm.contract_no = $("#contract_no").val();
  448. // dataForm.goods_category = $("#goods_category").val();
  449. // dataForm.goods_type = $("#goods_type").val();
  450. // dataForm.amount = $("#amount").val();
  451. // dataForm.price = $("#price").val();
  452. // dataForm.contract_value = $("#contract_value").val();
  453. // dataForm.receive_money = $("#receive_money").val();
  454. // dataForm.period_balance = $("#period_balance").val();
  455. // dataForm.actual_money = $("#actual_money").val();
  456. // dataForm.agency = $("#agency").val();
  457. // dataForm.base_price = $("#base_price").val();
  458. // dataForm.base_value = $("#base_value").val();
  459. // dataForm.shipping = $("#shipping").val();
  460. // dataForm.project = $("#project").val();
  461. // dataForm.current_balance = $("#current_balance").val();
  462. // dataForm.total_profit = $("#total_profit").val();
  463. // dataForm.seller = $("#seller").val();
  464. // dataForm.remark = $("#remark").val();
  465. // var data = $("#market-form").serializeArray();
  466. type = $('input[name="type"]:checked').val();
  467. if (type != 0) {
  468. base_price = Number($('#base_price2').val());
  469. } else {
  470. base_price = Number($('#base_price').val());
  471. }
  472. // console.log(type)
  473. // console.log(base_price)
  474. var data = {
  475. 'id': $('#id').val(),
  476. 'month': $('#month').val(),
  477. 'company': $('#company').val(),
  478. 'contract_no': $('#contract_no').val(),
  479. 'goods_category': $('#goods_category').val(),
  480. 'goods_type': $('#goods_type').val(),
  481. 'amount': $('#amount').val(),
  482. 'price': $('#price').val(),
  483. 'contract_value': $('#amount').val() * $('#price').val(),
  484. 'receive_money': $('#receive_money').val(),
  485. 'period_balance': $('#period_balance').val(),
  486. 'agency': $('#agency').val(),
  487. 'base_price': base_price,
  488. 'shipping': Number($('#shipping').val()),
  489. 'project': Number($('#project').val()),
  490. 'type': type,
  491. 'seller': $('#seller').val()
  492. }
  493. $.ajax({
  494. url: "/domarket.php?action=save",
  495. type: "POST",
  496. data: data,
  497. dataType: 'json',
  498. success: function(res) {
  499. if (res.code == 0) {
  500. dataForm.id = 0;
  501. $('#id').val(0)
  502. $('#myModal').modal('hide');
  503. $("#market-form")[0].reset();
  504. window.location.reload();
  505. } else {
  506. alert(res.msg);
  507. }
  508. return false;
  509. }
  510. });
  511. });
  512. </script>