|
|
@@ -0,0 +1,396 @@
|
|
|
+/**
|
|
|
+ * 委外加工详细
|
|
|
+ *
|
|
|
+ * @author hejq
|
|
|
+ * @date 2018-06-25 17:13
|
|
|
+ */
|
|
|
+
|
|
|
+
|
|
|
+define(['app/app'], function(app) {
|
|
|
+ app.register.controller('DeputyOrderDetailCtrl', ['$scope', '$rootScope', 'toaster', 'B2bDeputyOrder', '$stateParams', 'ngTableParams', 'BaseService', '$modal', 'B2bDecimalNumber', 'B2bCurrentRole', 'B2bDekeyValue', function ($scope, $rootScope, toaster, DeputyOrder, $stateParams, ngTableParams, BaseService, $modal, DecimalNumber, CurrentRole, DekeyValue) {
|
|
|
+ BaseService.scrollBackToTop();
|
|
|
+ $rootScope.active = 'buyer_order';
|
|
|
+ // 获取当前用户是否为普通用户
|
|
|
+ CurrentRole.isUser({}, {}, function (data) {
|
|
|
+ $scope.isUser = data.isUser;
|
|
|
+ });
|
|
|
+ var loadData = function () {
|
|
|
+ DeputyOrder.getOrderDetail({id: $stateParams.id}, {}, function (data) {
|
|
|
+ $scope.deOrder = data;
|
|
|
+ $scope.deOrder.$editing = true;
|
|
|
+ }, function (response) {
|
|
|
+ toaster.pop('error', '提示', response.data);
|
|
|
+ });
|
|
|
+ };
|
|
|
+ loadData();
|
|
|
+ //默认采购单号不重复
|
|
|
+ $scope.orderCodeEnable = true;
|
|
|
+ // 查询历史供应商
|
|
|
+ DeputyOrder.hisvendors({}, function (data) {
|
|
|
+ $scope.hisvendors = data;
|
|
|
+ }, function (response) {
|
|
|
+ toaster.pop('error', '提示', response.data);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 代采企业列表
|
|
|
+ DeputyOrder.deputyEnterprise({}, function (data) {
|
|
|
+ $scope.deputyEnterprises = data;
|
|
|
+ $scope.deOrder.deputyname = $scope.deputyEnterprises[0].deputyenname;
|
|
|
+ $scope.deOrder.deputyuu = $scope.deputyEnterprises[0].deputyenuu;
|
|
|
+ getPayMethod($scope.deOrder.deputyuu, 'paymentmethod');
|
|
|
+ });
|
|
|
+
|
|
|
+ var getPayMethod = function(enuu, key) {
|
|
|
+ // 获取我方付款支付方式默认值
|
|
|
+ DekeyValue.getValue({enuu: enuu, key: key}, function(data) {
|
|
|
+ $scope.methods = data.content;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新代采企业时更新费率
|
|
|
+ $scope.change = function (deputyname) {
|
|
|
+ DeputyOrder.deputyEnterprise({}, function (data) {
|
|
|
+ $scope.deputyEn = data;
|
|
|
+ angular.forEach($scope.deputyEn, function (en) {
|
|
|
+ if (deputyname == en.deputyenname) {
|
|
|
+ $scope.deputyuu = en.deputyenuu;
|
|
|
+ getPayMethod($scope.deputyuu, 'paymentmethod');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置付款企业信息
|
|
|
+ $scope.setPayComName = function() {
|
|
|
+ // 针对信扬客户,如果是RMB赋值默认值
|
|
|
+ if ($scope.deOrder.currency == 'RMB' && $scope.deOrder.deputyuu == 10044118) {
|
|
|
+ $scope.deOrder.paycomname = '深圳信扬国际经贸股份有限公司';
|
|
|
+ $scope.deOrder.paycomaddress= '深圳市前海深港合作区前湾一路1号A栋201室(入驻深圳市前海商务秘书有限公司)';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查找付款企业
|
|
|
+ $scope.dbfindPayCompany = function (deputyuu) {
|
|
|
+ var modalInstance = $modal.open({
|
|
|
+ templateUrl: 'static/tpl/index/purc/modal/payCompany.html',
|
|
|
+ controller: 'DbfindDeputyPayCompanyCtrl',
|
|
|
+ resolve: {
|
|
|
+ deputyuu: function () {
|
|
|
+ return deputyuu
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ modalInstance.result.then(function (data) {
|
|
|
+ $scope.deOrder.paycomname = data.enname;
|
|
|
+ $scope.deOrder.paycomaddress = data.address;
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除明细
|
|
|
+ $scope.del = function (index, id) {
|
|
|
+ DeputyOrder.deleteProdById({id: id}, {}, function (data) {
|
|
|
+ if (data.success) {
|
|
|
+ toaster.pop('success', '提示', data.success);
|
|
|
+ $scope.deOrder.deputyOrderItems.splice(index, 1)
|
|
|
+ }
|
|
|
+ if (data.error) {
|
|
|
+ toaster.pop('error', '提示', data.error);
|
|
|
+ }
|
|
|
+ $scope.deOrder.totalamount = 0;
|
|
|
+ $scope.deOrder.usdpayment = 0;
|
|
|
+ $scope.deOrder.orderamount = 0;
|
|
|
+ $scope.deOrder.totalpayament = 0;
|
|
|
+ angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
|
|
|
+ $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
|
|
|
+ $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
|
|
|
+ $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
|
|
|
+ $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
|
|
|
+ });
|
|
|
+ }, function (response) {
|
|
|
+ toaster.pop('error', '提示', response.data);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ //增加商品
|
|
|
+ $scope.add = function (index) {
|
|
|
+ if ($scope.deOrder.deputyOrderItems[index].prodcode == null) {
|
|
|
+ toaster.pop('info', '提示', '请先填写商品信息');
|
|
|
+ } else {
|
|
|
+ $scope.deOrder.deputyOrderItems.push(
|
|
|
+ {
|
|
|
+ prodname: null,
|
|
|
+ prodcode: null,
|
|
|
+ prodspec: null,
|
|
|
+ prodbrand: null,
|
|
|
+ amount: null,
|
|
|
+ unitprice: null,
|
|
|
+ remark: null,
|
|
|
+ orderprice: null
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // 导入商品信息
|
|
|
+ $scope.uplodaByBatch = function () {
|
|
|
+ var modalInstance = $modal.open({
|
|
|
+ templateUrl: 'static/view/usercenter/b2b/modal/uplodaByBatch.html',
|
|
|
+ controller: 'DeputyOrderUploadCtrl',
|
|
|
+ size: 'lg',
|
|
|
+ resolve: {}
|
|
|
+ });
|
|
|
+
|
|
|
+ modalInstance.result.then(function (data) {
|
|
|
+ angular.forEach(data, function (data) {
|
|
|
+ $scope.deOrder.deputyOrderItems.push(data);
|
|
|
+ for (var i = 0; i < $scope.deOrder.deputyOrderItems.length; i++) {
|
|
|
+ if ($scope.deOrder.deputyOrderItems[i].prodname == null) { // 如果没有填写就删除这行数据
|
|
|
+ $scope.deOrder.deputyOrderItems.splice(i, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ $scope.deOrder.totalamount = 0;
|
|
|
+ $scope.deOrder.usdpayment = 0;
|
|
|
+ $scope.deOrder.orderamount = 0;
|
|
|
+ $scope.deOrder.totalpayament = 0;
|
|
|
+ angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
|
|
|
+ $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
|
|
|
+ $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
|
|
|
+ $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
|
|
|
+ $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
|
|
|
+ });
|
|
|
+
|
|
|
+ }, function () {
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除商品
|
|
|
+ $scope.delItem = function (index) {
|
|
|
+ $scope.deOrder.deputyOrderItems.splice(index, 1);
|
|
|
+ };
|
|
|
+ var getService = function () {
|
|
|
+ return DeputyOrder.getProdList;
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.update = function () {
|
|
|
+ $scope.deOrder.$editing = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ $scope.cancel = function () {
|
|
|
+ $scope.deOrder.$editing = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检验订单编号是否存在
|
|
|
+ $scope.checkOrder = function (salecode, deputyuu) {
|
|
|
+ DeputyOrder.checkOrders({salecode: salecode, deputyuu: deputyuu}, {}, function (data) {
|
|
|
+ $scope.orderCodeEnable = true;
|
|
|
+ if (data.info) {
|
|
|
+ toaster.pop('error', '提示', data.info);
|
|
|
+ $scope.orderCodeEnable = false;
|
|
|
+ }
|
|
|
+ }, function (response) {
|
|
|
+ toaster.pop('error', '提示', response.data);
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ //计算采购单价
|
|
|
+ $scope.checkPrice = function (rate) {
|
|
|
+ $scope.deOrder.totalamount = 0;
|
|
|
+ $scope.deOrder.usdpayment = 0;
|
|
|
+ $scope.deOrder.orderamount = 0;
|
|
|
+ $scope.deOrder.totalpayament = 0;
|
|
|
+ if (rate == null) {
|
|
|
+ toaster.pop('info', '提示', '请先填入税率');
|
|
|
+ } else {
|
|
|
+ angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
|
|
|
+ item.purcprice = DecimalNumber.accMul(item.unitprice, (1 + rate / 100));
|
|
|
+ $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
|
|
|
+ $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
|
|
|
+ $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
|
|
|
+ $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取订单总价
|
|
|
+ $scope.totalPrice = function () {
|
|
|
+ $scope.deOrder.totalamount = 0;
|
|
|
+ $scope.deOrder.usdpayment = 0;
|
|
|
+ $scope.deOrder.orderamount = 0;
|
|
|
+ $scope.deOrder.totalpayament = 0;
|
|
|
+ angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
|
|
|
+ if(item.amount != null && item.unitprice != null && item.purcprice != null) {
|
|
|
+ $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
|
|
|
+ $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
|
|
|
+ $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
|
|
|
+ $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ $scope.checkresult = false;
|
|
|
+ var checkKeyword = function () {
|
|
|
+ if ($scope.deOrder.madealdate == null) {
|
|
|
+ toaster.pop('info', '提示', '主协议签订日期未选择');
|
|
|
+ } else if ($scope.deOrder.madealcode == null) {
|
|
|
+ toaster.pop('info', '提示', '主协议签订编号未填写');
|
|
|
+ } else if ($scope.deOrder.tervendor == null) {
|
|
|
+ toaster.pop('info', '提示', '终端供应商名称未填写');
|
|
|
+ } else if ($scope.deOrder.vendtel == null) {
|
|
|
+ toaster.pop('info', '提示', '电话号码未填写');
|
|
|
+ } else if ($scope.deOrder.venduser == null) {
|
|
|
+ toaster.pop('info', '提示', '联系人未填写');
|
|
|
+ } else if ($scope.deOrder.shipdate == null) {
|
|
|
+ toaster.pop('info', '提示', '供应商发货时间未选择');
|
|
|
+ } else if ($scope.deOrder.goodspacking == null) {
|
|
|
+ toaster.pop('info', '提示', '货物包装要求未填写');
|
|
|
+ } else if ($scope.deOrder.deliverymethod == null) {
|
|
|
+ toaster.pop('info', '提示', '供应商交货方式未填写');
|
|
|
+ } else if ($scope.deOrder.pickupmethod == null) {
|
|
|
+ toaster.pop('info', '提示', '我方提货方式未填写');
|
|
|
+ } else if ($scope.deOrder.paymentmethod == null) {
|
|
|
+ toaster.pop('info', '提示', '我方付款方式未填写');
|
|
|
+ } else if ($scope.deOrder.pickupdate == null) {
|
|
|
+ toaster.pop('info', '提示', '我方提货时间未选择');
|
|
|
+ } else if ($scope.deOrder.currency == null) {
|
|
|
+ toaster.pop('info', '提示', '交易币别未选择');
|
|
|
+ } else if ($scope.deOrder.deputyuu == null) {
|
|
|
+ toaster.pop('info', '提示', '代采企业未选择');
|
|
|
+ } else if ($scope.deOrder.salecode == null) {
|
|
|
+ toaster.pop('info', '提示', '订单编号未填写');
|
|
|
+ } else if ($scope.deOrder.paydeldate == null) {
|
|
|
+ toaster.pop('info', '提示', '我方付款提货时间未选择');
|
|
|
+ } else if ($scope.deOrder.riskmethod == null) {
|
|
|
+ toaster.pop('info', '提示', '风险承担方式未填写');
|
|
|
+ } else if ($scope.deOrder.taxpaymentmethod == null) {
|
|
|
+ toaster.pop('info', '提示', '运、税费承担方式');
|
|
|
+ } else if ($scope.deOrder.tervendaddress == null) {
|
|
|
+ toaster.pop('info', '提示', '终端供应商地址未填写');
|
|
|
+ } else if ($scope.deOrder.companyname == null) {
|
|
|
+ toaster.pop('info', '提示', '公司全称(英文)未填写');
|
|
|
+ } else if ($scope.deOrder.requirepaydate == null) {
|
|
|
+ toaster.pop('info', '提示', '要求付汇日期未选择');
|
|
|
+ } else if ($scope.deOrder.bankname == null) {
|
|
|
+ toaster.pop('info', '提示', '银行名称(英文)未填写');
|
|
|
+ } else if ($scope.deOrder.bankaccount == null) {
|
|
|
+ toaster.pop('info', '提示', '银行账号未填写');
|
|
|
+ } else if ($scope.deOrder.bankaddress == null) {
|
|
|
+ toaster.pop('info', '提示', '银行地址未填写');
|
|
|
+ } else if ($scope.deOrder.bankcode == null) {
|
|
|
+ toaster.pop('info', '提示', '银行代码未填写');
|
|
|
+ } else if ($scope.deOrder.salepocode == null) {
|
|
|
+ toaster.pop('info', '提示', '合同编号未填写');
|
|
|
+ } else if ($scope.deOrder.legalrepresent == null) {
|
|
|
+ toaster.pop('info', '提示', '供应商方法定代表人未填写');
|
|
|
+ } else if ($scope.deOrder.paycomname == null) {
|
|
|
+ toaster.pop('info', '提示', '付款公司未填写');
|
|
|
+ } else if ($scope.deOrder.paycomaddress == null) {
|
|
|
+ toaster.pop('info', '提示', '付款公司地址未填写');
|
|
|
+ } else if ($scope.deOrder.enfax == null) {
|
|
|
+ toaster.pop('info', '提示', '供应商方法人电话未填写');
|
|
|
+ } else if ($scope.deOrder.paydate == null) {
|
|
|
+ toaster.pop('info', '提示', '货款支付时间未选择');
|
|
|
+ } else if ($scope.deOrder.paymethod == null) {
|
|
|
+ toaster.pop('info', '提示', '货款支付方式未填写');
|
|
|
+ } else if ($scope.deOrder.deliverydate == null) {
|
|
|
+ toaster.pop('info', '提示', '交货时间未选择');
|
|
|
+ } else if (!$scope.orderCodeEnable) {
|
|
|
+ toaster.pop('info', '提示', '采购单号重复');
|
|
|
+ } else if ($scope.deOrder.currency == 'USD' && $scope.deOrder.totalpayament >= 300 * 10000) {
|
|
|
+ toaster.pop('error', '提示', '单张订单委托采购总金额不得超过300万美金');
|
|
|
+ } else if ($scope.deOrder.currency == 'RMB' && $scope.deOrder.totalpayament >= 1000 * 10000) {
|
|
|
+ toaster.pop('error', '提示', '单张订单委托采购总金额不得超过1000万人民币');
|
|
|
+ } else {
|
|
|
+ angular.forEach($scope.deOrder.deputyOrderItems, function (orderitem, index) {
|
|
|
+ if (orderitem.prodname == null) {
|
|
|
+ toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品名称未填写');
|
|
|
+ } else if (orderitem.prodcode == null) {
|
|
|
+ toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品编号未填写');
|
|
|
+ } else if (orderitem.prodspec == null) {
|
|
|
+ toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品规格未填写');
|
|
|
+ } else if (orderitem.prodbrand == null) {
|
|
|
+ toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品品牌未填写');
|
|
|
+ } else if (orderitem.amount == null) {
|
|
|
+ toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行数量未填写');
|
|
|
+ } else if (orderitem.unitprice == null) {
|
|
|
+ toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行单价未填写');
|
|
|
+ } else if (orderitem.purcprice == null) {
|
|
|
+ toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行订单单价未填写');
|
|
|
+ } else {
|
|
|
+ $scope.checkresult = true;
|
|
|
+ $scope.isSave = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存
|
|
|
+ $scope.isSave = false;
|
|
|
+ $scope.save = function (status) {
|
|
|
+ checkKeyword();
|
|
|
+ if ($scope.checkresult) {
|
|
|
+ $scope.deOrder.totalamount = 0;
|
|
|
+ $scope.deOrder.usdpayment = 0;
|
|
|
+ $scope.deOrder.orderamount = 0;
|
|
|
+ $scope.deOrder.totalpayament = 0;
|
|
|
+ angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
|
|
|
+ $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
|
|
|
+ $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
|
|
|
+ $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
|
|
|
+ $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
|
|
|
+ });
|
|
|
+ if ($scope.deOrder.deputyOrderItems[0].prodcode == null) {
|
|
|
+ toaster.pop('info', '提示', '您还未填写任何商品信息');
|
|
|
+ } else {
|
|
|
+ $scope.deOrder.entrystatus = status;
|
|
|
+ DeputyOrder.saveDeOrder({}, $scope.deOrder, function (data) {
|
|
|
+ if (data.id) {
|
|
|
+ toaster.pop('success', '提示', '保存成功');
|
|
|
+ loadData();
|
|
|
+ window.location.reload();
|
|
|
+ }
|
|
|
+ if (data.error) {
|
|
|
+ toaster.pop('error', '提示', '保存失败');
|
|
|
+ }
|
|
|
+ }, function (response) {
|
|
|
+ toaster.pop('error', '保存失败', response.data);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $scope.openDatePicker = function ($event, deOrder, openParam) {
|
|
|
+ $event.preventDefault();
|
|
|
+ $event.stopPropagation();
|
|
|
+ deOrder[openParam] = !deOrder[openParam];
|
|
|
+ };
|
|
|
+
|
|
|
+ //复制采购单
|
|
|
+ $scope.copyorder = function (id) {
|
|
|
+ DeputyOrder.copyOrder({id: id}, {}, function (data) {
|
|
|
+ if (data.id) {
|
|
|
+ toaster.pop('success', '提示', '复制生成单据成功');
|
|
|
+ window.location.hash = "#/purc/deputy/" + data.id;
|
|
|
+ }
|
|
|
+ if (data.error) {
|
|
|
+ toaster.pop('error', '提示', '保存失败');
|
|
|
+ }
|
|
|
+ }, function (response) {
|
|
|
+ toaster.pop('error', '提示', response.data);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除代采订单
|
|
|
+ $scope.clear = function (id) {
|
|
|
+ DeputyOrder.clearOrder({id: id}, {}, function (data) {
|
|
|
+ if (data.success) {
|
|
|
+ toaster.pop('success', '提示', data.success);
|
|
|
+ window.location.hash = "#/purc/deputy";
|
|
|
+ }
|
|
|
+ }, function (response) {
|
|
|
+ toaster.pop('error', '提示', response.data);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }]);
|
|
|
+})
|