|
@@ -288,6 +288,8 @@ func (c *StockManagerApiController) CreateWarehouse() {
|
288
|
288
|
|
289
|
289
|
license_number, _ := items["license_number"].(string)
|
290
|
290
|
|
|
291
|
+
|
|
292
|
+ register_number, _ := items["register_number"].(string)
|
291
|
293
|
//入库单表格
|
292
|
294
|
warehouseInfo := &models.WarehousingInfo{
|
293
|
295
|
ID: id,
|
|
@@ -313,9 +315,34 @@ func (c *StockManagerApiController) CreateWarehouse() {
|
313
|
315
|
PackingPrice: packing_price,
|
314
|
316
|
StorehouseId: storehouse_id,
|
315
|
317
|
IsCheck: 2,
|
|
318
|
+ RegisterNumber: register_number,
|
316
|
319
|
}
|
317
|
320
|
warehousingInfo = append(warehousingInfo, warehouseInfo)
|
318
|
321
|
|
|
322
|
+ flow := &models.VmStockFlow{
|
|
323
|
+ WarehousingOrder: warehousing.WarehousingOrder,
|
|
324
|
+ WarehousingId: warehousing.ID,
|
|
325
|
+ GoodId: good_id,
|
|
326
|
+ Number: number,
|
|
327
|
+ ProductDate: productDates,
|
|
328
|
+ ExpireDate: expiryDates,
|
|
329
|
+ Count: warehousing_count,
|
|
330
|
+ Price: price,
|
|
331
|
+ Status: 1,
|
|
332
|
+ Ctime: ctime,
|
|
333
|
+ UserOrgId: adminUserInfo.CurrentOrgId,
|
|
334
|
+ Manufacturer: manufacturer,
|
|
335
|
+ Dealer: dealer,
|
|
336
|
+ LicenseNumber: license_number,
|
|
337
|
+ IsEdit: 1,
|
|
338
|
+ Creator: adminUserInfo.AdminUser.Id,
|
|
339
|
+ SystemTime: operation_time,
|
|
340
|
+ ConsumableType: 1,
|
|
341
|
+ WarehousingDetailId: warehouseInfo.ID,
|
|
342
|
+ StorehouseId: storehouse_id,
|
|
343
|
+ RegisterNumber: register_number,
|
|
344
|
+ }
|
|
345
|
+ stockFlow = append(stockFlow, flow)
|
319
|
346
|
}
|
320
|
347
|
}
|
321
|
348
|
}
|
|
@@ -323,6 +350,30 @@ func (c *StockManagerApiController) CreateWarehouse() {
|
323
|
350
|
for _, item := range warehousingInfo {
|
324
|
351
|
if item.ID == 0 {
|
325
|
352
|
service.CreatedWarehouseingDetail(item)
|
|
353
|
+ service.CreatedWarehouseingDetail(item)
|
|
354
|
+ warehousinginfo, _ := service.GetLastWarehousingInfo(item.GoodId)
|
|
355
|
+ flow := models.VmStockFlow{
|
|
356
|
+ WarehousingOrder: item.WarehousingOrder,
|
|
357
|
+ WarehousingId: item.WarehousingId,
|
|
358
|
+ GoodId: item.GoodId,
|
|
359
|
+ Number: item.Number,
|
|
360
|
+ ProductDate: item.ProductDate,
|
|
361
|
+ ExpireDate: item.ExpiryDate,
|
|
362
|
+ Count: item.StockCount,
|
|
363
|
+ Price: item.Price,
|
|
364
|
+ Status: 1,
|
|
365
|
+ Ctime: ctime,
|
|
366
|
+ UserOrgId: item.OrgId,
|
|
367
|
+ Manufacturer: item.Manufacturer,
|
|
368
|
+ Dealer: item.Dealer,
|
|
369
|
+ LicenseNumber: item.LicenseNumber,
|
|
370
|
+ IsEdit: 1,
|
|
371
|
+ Creator: adminUserInfo.AdminUser.Id,
|
|
372
|
+ SystemTime: operation_time,
|
|
373
|
+ ConsumableType: 1,
|
|
374
|
+ WarehousingDetailId: warehousinginfo.ID,
|
|
375
|
+ StorehouseId: storehouse_id,
|
|
376
|
+ RegisterNumber: item.RegisterNumber,
|
326
|
377
|
}
|
327
|
378
|
if item.ID > 0 {
|
328
|
379
|
service.UpdateWarehouseDetail(item, item.ID)
|
|
@@ -564,6 +615,7 @@ func (c *StockManagerApiController) EditWarehouse() {
|
564
|
615
|
manufacturer := int64(items["manufacturer"].(float64))
|
565
|
616
|
dealer := int64(items["dealer"].(float64))
|
566
|
617
|
license_number, _ := items["license_number"].(string)
|
|
618
|
+ register_number, _ := items["register_number"].(string)
|
567
|
619
|
if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
|
568
|
620
|
utils.ErrorLog("id")
|
569
|
621
|
c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
@@ -595,6 +647,7 @@ func (c *StockManagerApiController) EditWarehouse() {
|
595
|
647
|
PackingPrice: packing_price,
|
596
|
648
|
StorehouseId: storehouse_id,
|
597
|
649
|
IsCheck: 2,
|
|
650
|
+ RegisterNumber: register_number,
|
598
|
651
|
}
|
599
|
652
|
warehousingInfo = append(warehousingInfo, warehouseInfo)
|
600
|
653
|
|
|
@@ -622,6 +675,7 @@ func (c *StockManagerApiController) EditWarehouse() {
|
622
|
675
|
LicenseNumber: license_number,
|
623
|
676
|
PackingPrice: packing_price,
|
624
|
677
|
StorehouseId: storehouse_id,
|
|
678
|
+ RegisterNumber: register_number,
|
625
|
679
|
}
|
626
|
680
|
upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
|
627
|
681
|
|
|
@@ -646,6 +700,7 @@ func (c *StockManagerApiController) EditWarehouse() {
|
646
|
700
|
ConsumableType: 1,
|
647
|
701
|
WarehousingDetailId: warehouseInfo.ID,
|
648
|
702
|
StorehouseId: storehouse_id,
|
|
703
|
+ RegisterNumber: register_number,
|
649
|
704
|
}
|
650
|
705
|
|
651
|
706
|
stockFlow = append(stockFlow, flow)
|
|
@@ -656,11 +711,202 @@ func (c *StockManagerApiController) EditWarehouse() {
|
656
|
711
|
var errs error
|
657
|
712
|
if len(warehousingInfo) > 0 {
|
658
|
713
|
errs = service.CreateWarehousingInfo(warehousingInfo)
|
|
714
|
+
|
|
715
|
+ for _, its := range warehousingInfo {
|
|
716
|
+ //查询
|
|
717
|
+ info, _ := service.GetLastGoodWarehouseInfo(its.GoodId)
|
|
718
|
+ flows := models.VmStockFlow{
|
|
719
|
+ WarehousingOrder: info.WarehousingOrder,
|
|
720
|
+ WarehousingId: info.ID,
|
|
721
|
+ GoodId: info.GoodId,
|
|
722
|
+ Number: info.Number,
|
|
723
|
+ ProductDate: info.ProductDate,
|
|
724
|
+ ExpireDate: info.ExpiryDate,
|
|
725
|
+ Count: info.WarehousingCount,
|
|
726
|
+ Price: info.Price,
|
|
727
|
+ Status: 1,
|
|
728
|
+ Ctime: ctime,
|
|
729
|
+ UserOrgId: adminUserInfo.CurrentOrgId,
|
|
730
|
+ Manufacturer: info.Manufacturer,
|
|
731
|
+ Dealer: info.Dealer,
|
|
732
|
+ LicenseNumber: info.LicenseNumber,
|
|
733
|
+ IsEdit: 1,
|
|
734
|
+ Creator: adminUserInfo.AdminUser.Id,
|
|
735
|
+ SystemTime: ctime,
|
|
736
|
+ ConsumableType: 1,
|
|
737
|
+ WarehousingDetailId: info.ID,
|
|
738
|
+ StorehouseId: storehouse_id,
|
|
739
|
+ RegisterNumber: info.RegisterNumber,
|
|
740
|
+ }
|
|
741
|
+ _, errcodescode := service.GetGoodStockFlowInfo(info.ID, info.GoodId)
|
|
742
|
+
|
|
743
|
+ if errcodescode == gorm.ErrRecordNotFound {
|
|
744
|
+ service.CreateStockFlowOne(flows)
|
|
745
|
+ }
|
|
746
|
+
|
|
747
|
+ //改变库存
|
|
748
|
+ good, _ := service.GetLastInfoMationById(info.GoodId)
|
|
749
|
+ warhouseCount := strconv.FormatInt(info.WarehousingCount, 10)
|
|
750
|
+ total, _ := strconv.ParseFloat(warhouseCount, 64)
|
|
751
|
+ goodInfo := models.GoodInfo{
|
|
752
|
+ Total: good.Total + total,
|
|
753
|
+ }
|
|
754
|
+ errcodescode = service.UpdateGoodInfoMation(info.GoodId, goodInfo)
|
|
755
|
+ fmt.Println(errcodescode)
|
|
756
|
+
|
|
757
|
+ //查询该机构默认仓库
|
|
758
|
+ storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
|
|
759
|
+ //查询剩余库存
|
|
760
|
+ goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, info.GoodId, adminUserInfo.CurrentOrgId)
|
|
761
|
+ var sum_count int64
|
|
762
|
+ var sum_in_count int64
|
|
763
|
+ for _, item := range goodList {
|
|
764
|
+ sum_count += item.StockCount
|
|
765
|
+ sum_in_count += item.WarehousingCount
|
|
766
|
+ }
|
|
767
|
+ service.UpdateGoodByGoodId(info.GoodId, sum_count, sum_in_count, info.OrgId)
|
|
768
|
+ }
|
659
|
769
|
}
|
660
|
770
|
|
661
|
771
|
if len(upDateWarehousingInfo) > 0 {
|
662
|
772
|
for _, item := range upDateWarehousingInfo {
|
663
|
773
|
service.UpdateWarehouseInfoByGoodIdOne(item, item.ID)
|
|
774
|
+ var total int64
|
|
775
|
+ //获取该批次该型号的库存
|
|
776
|
+ info, _ := service.GetLastWarehousingByIdOne(item.ID, item.GoodId)
|
|
777
|
+
|
|
778
|
+ //增加库存
|
|
779
|
+ if item.WarehousingCount > info.WarehousingCount {
|
|
780
|
+
|
|
781
|
+ total = item.WarehousingCount - info.WarehousingCount
|
|
782
|
+ goodinfo := models.WarehousingInfo{
|
|
783
|
+ WarehousingCount: item.WarehousingCount,
|
|
784
|
+ StockCount: info.StockCount + total,
|
|
785
|
+ Price: item.Price,
|
|
786
|
+ Manufacturer: item.Manufacturer,
|
|
787
|
+ Number: item.Number,
|
|
788
|
+ ProductDate: item.ProductDate,
|
|
789
|
+ ExpiryDate: item.ExpiryDate,
|
|
790
|
+ LicenseNumber: item.LicenseNumber,
|
|
791
|
+ Dealer: item.Dealer,
|
|
792
|
+ Remark: item.Remark,
|
|
793
|
+ PackingPrice: item.PackingPrice,
|
|
794
|
+ StorehouseId: storehouse_id,
|
|
795
|
+ RegisterNumber: item.RegisterNumber,
|
|
796
|
+ }
|
|
797
|
+
|
|
798
|
+ //改变库存
|
|
799
|
+ good, _ := service.GetLastInfoMationById(info.GoodId)
|
|
800
|
+ warhouseCount := strconv.FormatInt(total, 10)
|
|
801
|
+ all_total, _ := strconv.ParseFloat(warhouseCount, 64)
|
|
802
|
+ goodInfo := models.GoodInfo{
|
|
803
|
+ Total: good.Total + all_total,
|
|
804
|
+ }
|
|
805
|
+ service.UpdateGoodInfoMation(info.GoodId, goodInfo)
|
|
806
|
+ service.UpdateWarehouseInfoByGoodIdOne(goodinfo, item.ID)
|
|
807
|
+ //查询该机构默认仓库
|
|
808
|
+ storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
|
|
809
|
+ //查询剩余库存
|
|
810
|
+ goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
|
|
811
|
+ var sum_count int64
|
|
812
|
+ var sum_in_count int64
|
|
813
|
+ for _, item := range goodList {
|
|
814
|
+ sum_count += item.StockCount
|
|
815
|
+ sum_in_count += item.WarehousingCount
|
|
816
|
+ }
|
|
817
|
+ service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, item.OrgId)
|
|
818
|
+ }
|
|
819
|
+
|
|
820
|
+ if item.WarehousingCount < info.WarehousingCount {
|
|
821
|
+
|
|
822
|
+ total = info.WarehousingCount - item.WarehousingCount
|
|
823
|
+ goodinfo := models.WarehousingInfo{
|
|
824
|
+ WarehousingCount: item.WarehousingCount,
|
|
825
|
+ StockCount: info.StockCount - total,
|
|
826
|
+ Price: item.Price,
|
|
827
|
+ Manufacturer: item.Manufacturer,
|
|
828
|
+ Number: item.Number,
|
|
829
|
+ ProductDate: item.ProductDate,
|
|
830
|
+ ExpiryDate: item.ExpiryDate,
|
|
831
|
+ LicenseNumber: item.LicenseNumber,
|
|
832
|
+ Dealer: item.Dealer,
|
|
833
|
+ Remark: item.Remark,
|
|
834
|
+ PackingPrice: item.PackingPrice,
|
|
835
|
+ StorehouseId: storehouse_id,
|
|
836
|
+ RegisterNumber: item.RegisterNumber,
|
|
837
|
+ }
|
|
838
|
+
|
|
839
|
+ //改变库存
|
|
840
|
+ good, _ := service.GetLastInfoMationById(info.GoodId)
|
|
841
|
+ warhouseCount := strconv.FormatInt(total, 10)
|
|
842
|
+ all_total, _ := strconv.ParseFloat(warhouseCount, 64)
|
|
843
|
+ goodInfo := models.GoodInfo{
|
|
844
|
+ Total: good.Total - all_total,
|
|
845
|
+ }
|
|
846
|
+ service.UpdateGoodInfoMation(info.GoodId, goodInfo)
|
|
847
|
+ service.UpdateWarehouseInfoByGoodIdOne(goodinfo, item.ID)
|
|
848
|
+ //查询该机构默认仓库
|
|
849
|
+ storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
|
|
850
|
+ //查询剩余库存
|
|
851
|
+ goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
|
|
852
|
+ var sum_count int64
|
|
853
|
+ var sum_in_count int64
|
|
854
|
+ for _, item := range goodList {
|
|
855
|
+ sum_count += item.StockCount
|
|
856
|
+ sum_in_count += item.WarehousingCount
|
|
857
|
+ }
|
|
858
|
+ service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, item.OrgId)
|
|
859
|
+ }
|
|
860
|
+
|
|
861
|
+ if item.WarehousingCount == info.WarehousingCount {
|
|
862
|
+ goodinfo := models.WarehousingInfo{
|
|
863
|
+ WarehousingCount: item.WarehousingCount,
|
|
864
|
+ StockCount: info.StockCount,
|
|
865
|
+ Price: item.Price,
|
|
866
|
+ Manufacturer: item.Manufacturer,
|
|
867
|
+ Number: item.Number,
|
|
868
|
+ ProductDate: item.ProductDate,
|
|
869
|
+ ExpiryDate: item.ExpiryDate,
|
|
870
|
+ LicenseNumber: item.LicenseNumber,
|
|
871
|
+ Dealer: item.Dealer,
|
|
872
|
+ Remark: item.Remark,
|
|
873
|
+ PackingPrice: item.PackingPrice,
|
|
874
|
+ StorehouseId: storehouse_id,
|
|
875
|
+ RegisterNumber: item.RegisterNumber,
|
|
876
|
+ }
|
|
877
|
+ service.UpdateWarehouseInfoByGoodIdOne(goodinfo, item.ID)
|
|
878
|
+ //查询该机构默认仓库
|
|
879
|
+ storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
|
|
880
|
+ //查询剩余库存
|
|
881
|
+ goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
|
|
882
|
+ var sum_count int64
|
|
883
|
+ var sum_in_count int64
|
|
884
|
+ for _, item := range goodList {
|
|
885
|
+ sum_count += item.StockCount
|
|
886
|
+ sum_in_count += item.WarehousingCount
|
|
887
|
+ }
|
|
888
|
+ service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, item.OrgId)
|
|
889
|
+ }
|
|
890
|
+
|
|
891
|
+ }
|
|
892
|
+ }
|
|
893
|
+
|
|
894
|
+ if len(stockFlow) > 0 {
|
|
895
|
+ for _, item := range stockFlow {
|
|
896
|
+ flow := models.VmStockFlow{
|
|
897
|
+ Count: item.Count,
|
|
898
|
+ Number: item.Number,
|
|
899
|
+ ProductDate: item.ProductDate,
|
|
900
|
+ ExpireDate: item.ExpireDate,
|
|
901
|
+ Price: item.Price,
|
|
902
|
+ Manufacturer: item.Manufacturer,
|
|
903
|
+ Dealer: item.Dealer,
|
|
904
|
+ LicenseNumber: item.LicenseNumber,
|
|
905
|
+ StorehouseId: storehouse_id,
|
|
906
|
+ RegisterNumber: item.RegisterNumber,
|
|
907
|
+ }
|
|
908
|
+ parseDateErr := service.UpdatedStockFlowByGoodIdOne(item.WarehousingId, item.GoodId, flow)
|
|
909
|
+ fmt.Println(parseDateErr)
|
664
|
910
|
}
|
665
|
911
|
}
|
666
|
912
|
|
|
@@ -1220,6 +1466,8 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
|
1220
|
1466
|
}
|
1221
|
1467
|
license_number := items["license_number"].(string)
|
1222
|
1468
|
|
|
1469
|
+
|
|
1470
|
+ register_number := items["register_number"].(string)
|
1223
|
1471
|
warehouseOutInfo := &models.WarehouseOutInfo{
|
1224
|
1472
|
ID: id,
|
1225
|
1473
|
WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
|
|
@@ -1246,6 +1494,7 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
|
1246
|
1494
|
BuyPrice: buy_price,
|
1247
|
1495
|
StockCount: stock_count,
|
1248
|
1496
|
IsCheck: 2,
|
|
1497
|
+ RegisterNumber: register_number,
|
1249
|
1498
|
}
|
1250
|
1499
|
warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
|
1251
|
1500
|
|
|
@@ -1576,6 +1825,8 @@ func (c *StockManagerApiController) EditWarehouseOut() {
|
1576
|
1825
|
|
1577
|
1826
|
license_number := items["license_number"].(string)
|
1578
|
1827
|
|
|
1828
|
+ register_number := items["register_number"].(string)
|
|
1829
|
+
|
1579
|
1830
|
timeLayout := "2006-01-02"
|
1580
|
1831
|
loc, _ := time.LoadLocation("Local")
|
1581
|
1832
|
expiry_date := items["expiry_date"].(string)
|
|
@@ -1688,6 +1939,7 @@ func (c *StockManagerApiController) EditWarehouseOut() {
|
1688
|
1939
|
StorehouseId: storehouse_id,
|
1689
|
1940
|
AdminUserId: admin_user_id,
|
1690
|
1941
|
StockCount: stock_count,
|
|
1942
|
+ RegisterNumber: register_number,
|
1691
|
1943
|
}
|
1692
|
1944
|
upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
|
1693
|
1945
|
}
|
|
@@ -1980,6 +2232,276 @@ func (c *StockManagerApiController) EditWarehouseOut() {
|
1980
|
2232
|
//}
|
1981
|
2233
|
//service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, item.OrgId)
|
1982
|
2234
|
|
|
2235
|
+ //1.查询该耗材该批次的最后一次出库记录
|
|
2236
|
+ lastGood, _ := service.GetLastGoodInformationByGoodId(item.GoodId, item.WarehouseInfotId, item.OrgId)
|
|
2237
|
+
|
|
2238
|
+ //如果出库数量大于 最后一次批次的数量(那么要进行出库)
|
|
2239
|
+
|
|
2240
|
+ if item.Count > lastGood.Count {
|
|
2241
|
+
|
|
2242
|
+ //查询该耗材是否还有库存
|
|
2243
|
+ warehouseinfo, _ := service.GetTotalCountByGoodId(item.GoodId, item.StorehouseId)
|
|
2244
|
+
|
|
2245
|
+ //无库存
|
|
2246
|
+ if warehouseinfo.StockCount <= 0 {
|
|
2247
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
2248
|
+ "msg": "5",
|
|
2249
|
+ })
|
|
2250
|
+ return
|
|
2251
|
+ }
|
|
2252
|
+
|
|
2253
|
+ //有库存,进行出库,调用出库接口
|
|
2254
|
+ if warehouseinfo.StockCount > 0 {
|
|
2255
|
+ var total int64
|
|
2256
|
+ var stock_cout int64
|
|
2257
|
+ var total_count int64
|
|
2258
|
+ //计算和最后一次出库数据的差
|
|
2259
|
+ total = item.Count - lastGood.Count
|
|
2260
|
+
|
|
2261
|
+ if total > warehouseinfo.StockCount {
|
|
2262
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
2263
|
+ "msg": "6",
|
|
2264
|
+ })
|
|
2265
|
+ return
|
|
2266
|
+ }
|
|
2267
|
+ //获取该耗材该批次的剩余库存量
|
|
2268
|
+ info, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
|
|
2269
|
+
|
|
2270
|
+ //判断该批次的剩余库存 和出库的库存进行比较
|
|
2271
|
+ //如果出库的库存大于该批次的剩余库存,那么需要出库下一批次的库存
|
|
2272
|
+
|
|
2273
|
+ if total > info.StockCount {
|
|
2274
|
+ //计算出库和该批次相差的库存
|
|
2275
|
+ total_count = item.Count - info.StockCount
|
|
2276
|
+ //清空本批次次库存
|
|
2277
|
+ service.DeleteWarehouseInfo(item.WarehouseInfotId)
|
|
2278
|
+ //调用出库逻辑
|
|
2279
|
+ parseDateErr := service.ConsumablesDeliveryTwo(item.OrgId, item, total_count)
|
|
2280
|
+ if parseDateErr != nil {
|
|
2281
|
+ utils.ErrorLog(errs.Error())
|
|
2282
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
|
|
2283
|
+ return
|
|
2284
|
+ }
|
|
2285
|
+ }
|
|
2286
|
+ //如果与上次比的库存小于或等于于该批次的剩余库存,那么需要该批次出库
|
|
2287
|
+ if total <= info.StockCount {
|
|
2288
|
+ stock_cout = lastGood.Count + total
|
|
2289
|
+ fmt.Println(stock_cout)
|
|
2290
|
+ //扣减库存
|
|
2291
|
+ warehouse := models.WarehousingInfo{
|
|
2292
|
+ StockCount: info.StockCount - total,
|
|
2293
|
+ }
|
|
2294
|
+ errs := service.UpdateWarehousingInfo(warehouse, info.ID)
|
|
2295
|
+
|
|
2296
|
+ warehouseOutInfo := &models.WarehouseOutInfo{
|
|
2297
|
+ WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
|
|
2298
|
+ WarehouseOutId: id,
|
|
2299
|
+ WarehouseInfotId: item.WarehouseInfotId,
|
|
2300
|
+ Status: 1,
|
|
2301
|
+ Ctime: time.Now().Unix(),
|
|
2302
|
+ Remark: item.Remark,
|
|
2303
|
+ OrgId: item.OrgId,
|
|
2304
|
+ Type: 1,
|
|
2305
|
+ Manufacturer: item.Manufacturer,
|
|
2306
|
+ Dealer: item.Dealer,
|
|
2307
|
+ IsSys: 0,
|
|
2308
|
+ SysRecordTime: item.SysRecordTime,
|
|
2309
|
+ GoodTypeId: item.GoodTypeId,
|
|
2310
|
+ GoodId: item.GoodId,
|
|
2311
|
+ ExpiryDate: item.ExpiryDate,
|
|
2312
|
+ ProductDate: item.ProductDate,
|
|
2313
|
+ Number: item.Number,
|
|
2314
|
+ Price: item.Price,
|
|
2315
|
+ LicenseNumber: item.LicenseNumber,
|
|
2316
|
+ Count: item.Count,
|
|
2317
|
+ ConsumableType: 2,
|
|
2318
|
+ StorehouseId: item.StorehouseId,
|
|
2319
|
+ AdminUserId: item.AdminUserId,
|
|
2320
|
+ StockCount: item.StockCount,
|
|
2321
|
+ RegisterNumber: item.RegisterNumber,
|
|
2322
|
+ }
|
|
2323
|
+
|
|
2324
|
+ //查询是否存在
|
|
2325
|
+ _, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
|
|
2326
|
+ if errcode == gorm.ErrRecordNotFound {
|
|
2327
|
+
|
|
2328
|
+ errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
|
|
2329
|
+ if errOne != nil {
|
|
2330
|
+ utils.ErrorLog(errs.Error())
|
|
2331
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
|
|
2332
|
+ return
|
|
2333
|
+ }
|
|
2334
|
+ } else if errcode == nil {
|
|
2335
|
+ service.UpDateWarehouseOutInfo(item)
|
|
2336
|
+ //更新流水
|
|
2337
|
+ flow := models.VmStockFlow{
|
|
2338
|
+ Number: item.Number,
|
|
2339
|
+ LicenseNumber: item.LicenseNumber,
|
|
2340
|
+ Count: item.Count,
|
|
2341
|
+ Manufacturer: item.Manufacturer,
|
|
2342
|
+ Dealer: item.Dealer,
|
|
2343
|
+ ProductDate: item.ProductDate,
|
|
2344
|
+ ExpireDate: item.ExpiryDate,
|
|
2345
|
+ Price: item.Price,
|
|
2346
|
+ StorehouseId: item.StorehouseId,
|
|
2347
|
+ AdminUserId: item.AdminUserId,
|
|
2348
|
+ StockCount: item.StockCount,
|
|
2349
|
+ RegisterNumber: item.RegisterNumber,
|
|
2350
|
+ }
|
|
2351
|
+ service.UpdateStockFlowByDetailId(flow, item.ID)
|
|
2352
|
+
|
|
2353
|
+ goodInfo := models.GoodInfo{
|
|
2354
|
+ Manufacturer: item.Manufacturer,
|
|
2355
|
+ Dealer: item.Dealer,
|
|
2356
|
+ }
|
|
2357
|
+ service.UpdatedGoodInfo(goodInfo, item.GoodId)
|
|
2358
|
+ }
|
|
2359
|
+ }
|
|
2360
|
+ }
|
|
2361
|
+ }
|
|
2362
|
+
|
|
2363
|
+ var last_count int64
|
|
2364
|
+ var all_total int64
|
|
2365
|
+ var stock_total int64
|
|
2366
|
+ //如果退库数量小于最后一次批次的数量(要么要进行退库)
|
|
2367
|
+ if item.Count < lastGood.Count {
|
|
2368
|
+
|
|
2369
|
+ //退库数量和最后一次出库数据进行计算
|
|
2370
|
+ last_count = lastGood.Count - item.Count
|
|
2371
|
+
|
|
2372
|
+ //获取该耗材该批次的剩余库存量
|
|
2373
|
+ infoInfo, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
|
|
2374
|
+
|
|
2375
|
+ //退库数量和最后一次出库数据进行计算的差 加上 剩余库存的数量与 该批次的入库数量进行比较
|
|
2376
|
+ all_total = last_count + infoInfo.StockCount
|
|
2377
|
+
|
|
2378
|
+ //如果库存大于总数量,则退回到这个批次
|
|
2379
|
+
|
|
2380
|
+ if infoInfo.WarehousingCount > all_total {
|
|
2381
|
+ stock_total = last_count + infoInfo.StockCount
|
|
2382
|
+
|
|
2383
|
+ //退回该批次,计算数量
|
|
2384
|
+ warehousingInfoOne := models.WarehousingInfo{
|
|
2385
|
+ StockCount: stock_total,
|
|
2386
|
+ ID: item.WarehouseInfotId,
|
|
2387
|
+ OrgId: item.OrgId,
|
|
2388
|
+ StorehouseId: item.StorehouseId,
|
|
2389
|
+ }
|
|
2390
|
+
|
|
2391
|
+ parseDateErr := service.UpdateWarehousingInfo(warehousingInfoOne, item.WarehouseInfotId)
|
|
2392
|
+
|
|
2393
|
+ fmt.Println("parseDateErr", parseDateErr)
|
|
2394
|
+ //插入一条新纪录
|
|
2395
|
+ warehouseOutInfoThree := &models.WarehouseOutInfo{
|
|
2396
|
+ WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
|
|
2397
|
+ WarehouseOutId: id,
|
|
2398
|
+ WarehouseInfotId: item.WarehouseInfotId,
|
|
2399
|
+ Status: 1,
|
|
2400
|
+ Ctime: time.Now().Unix(),
|
|
2401
|
+ Remark: item.Remark,
|
|
2402
|
+ OrgId: item.OrgId,
|
|
2403
|
+ Type: 1,
|
|
2404
|
+ Manufacturer: item.Manufacturer,
|
|
2405
|
+ Dealer: item.Dealer,
|
|
2406
|
+ IsSys: 0,
|
|
2407
|
+ GoodTypeId: item.GoodTypeId,
|
|
2408
|
+ GoodId: item.GoodId,
|
|
2409
|
+ ExpiryDate: item.ExpiryDate,
|
|
2410
|
+ ProductDate: item.ProductDate,
|
|
2411
|
+ Number: item.Number,
|
|
2412
|
+ Price: item.Price,
|
|
2413
|
+ LicenseNumber: item.LicenseNumber,
|
|
2414
|
+ ConsumableType: 2,
|
|
2415
|
+ Count: item.Count,
|
|
2416
|
+ StorehouseId: item.StorehouseId,
|
|
2417
|
+ AdminUserId: item.AdminUserId,
|
|
2418
|
+ StockCount: item.StockCount,
|
|
2419
|
+ RegisterNumber: item.RegisterNumber,
|
|
2420
|
+ }
|
|
2421
|
+ //查询是否存在
|
|
2422
|
+ _, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
|
|
2423
|
+ if errcode == gorm.ErrRecordNotFound {
|
|
2424
|
+ errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfoThree)
|
|
2425
|
+ if errOne != nil {
|
|
2426
|
+ utils.ErrorLog(errs.Error())
|
|
2427
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
|
|
2428
|
+ return
|
|
2429
|
+ }
|
|
2430
|
+
|
|
2431
|
+ } else if errcode == nil {
|
|
2432
|
+ service.UpDateWarehouseOutInfo(item)
|
|
2433
|
+ flow := models.VmStockFlow{
|
|
2434
|
+ Number: item.Number,
|
|
2435
|
+ LicenseNumber: item.LicenseNumber,
|
|
2436
|
+ Count: item.Count,
|
|
2437
|
+ Manufacturer: item.Manufacturer,
|
|
2438
|
+ Dealer: item.Dealer,
|
|
2439
|
+ ProductDate: item.ProductDate,
|
|
2440
|
+ ExpireDate: item.ExpiryDate,
|
|
2441
|
+ Price: item.Price,
|
|
2442
|
+ StorehouseId: item.StorehouseId,
|
|
2443
|
+ AdminUserId: item.AdminUserId,
|
|
2444
|
+ StockCount: item.StockCount,
|
|
2445
|
+ RegisterNumber: item.RegisterNumber,
|
|
2446
|
+ }
|
|
2447
|
+ service.UpdateStockFlowByDetailId(flow, item.ID)
|
|
2448
|
+ goodInfo := models.GoodInfo{
|
|
2449
|
+ Manufacturer: item.Manufacturer,
|
|
2450
|
+ Dealer: item.Dealer,
|
|
2451
|
+ }
|
|
2452
|
+ service.UpdatedGoodInfo(goodInfo, item.GoodId)
|
|
2453
|
+
|
|
2454
|
+ }
|
|
2455
|
+ }
|
|
2456
|
+
|
|
2457
|
+ //如果库存小于总数量,则报错提醒,该批次的退库数据大于入库数据了无法退库,则需要退库到另一个批次
|
|
2458
|
+ if infoInfo.WarehousingCount < all_total {
|
|
2459
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
2460
|
+ "msg": "6",
|
|
2461
|
+ })
|
|
2462
|
+ return
|
|
2463
|
+ }
|
|
2464
|
+ }
|
|
2465
|
+
|
|
2466
|
+ if item.Count == lastGood.Count {
|
|
2467
|
+
|
|
2468
|
+ errs = service.UpDateWarehouseOutInfo(item)
|
|
2469
|
+ flow := models.VmStockFlow{
|
|
2470
|
+ Number: item.Number,
|
|
2471
|
+ LicenseNumber: item.LicenseNumber,
|
|
2472
|
+ Count: item.Count,
|
|
2473
|
+ Manufacturer: item.Manufacturer,
|
|
2474
|
+ Dealer: item.Dealer,
|
|
2475
|
+ ProductDate: item.ProductDate,
|
|
2476
|
+ ExpireDate: item.ExpiryDate,
|
|
2477
|
+ Price: item.Price,
|
|
2478
|
+ StorehouseId: item.StorehouseId,
|
|
2479
|
+ AdminUserId: item.AdminUserId,
|
|
2480
|
+ BuyPrice: item.BuyPrice,
|
|
2481
|
+ StockCount: item.StockCount,
|
|
2482
|
+ RegisterNumber: item.RegisterNumber,
|
|
2483
|
+ }
|
|
2484
|
+ service.UpdateStockFlowByDetailId(flow, item.ID)
|
|
2485
|
+ goodInfo := models.GoodInfo{
|
|
2486
|
+ Manufacturer: item.Manufacturer,
|
|
2487
|
+ Dealer: item.Dealer,
|
|
2488
|
+ }
|
|
2489
|
+ service.UpdatedGoodInfo(goodInfo, item.GoodId)
|
|
2490
|
+
|
|
2491
|
+ }
|
|
2492
|
+
|
|
2493
|
+ //查询该机构默认仓库
|
|
2494
|
+ storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
|
|
2495
|
+ //查询剩余库存
|
|
2496
|
+ goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
|
|
2497
|
+ var sum_count int64
|
|
2498
|
+ var sum_in_count int64
|
|
2499
|
+ for _, item := range goodList {
|
|
2500
|
+ sum_count += item.StockCount
|
|
2501
|
+ sum_in_count += item.WarehousingCount
|
|
2502
|
+ }
|
|
2503
|
+ service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, item.OrgId)
|
|
2504
|
+
|
1983
|
2505
|
}
|
1984
|
2506
|
}
|
1985
|
2507
|
|