//Bu kural Satınalma türündeki siparişlerin tamamından Satınalma irsaliyesi oluşturur. //Normal malzemei, takipli ve varyantlı malzemeler için çalışır. //Takipli malzemeler için random takip numarası, üretim tarihi ve son kullanım tarihi oluşturur. //Serili malzemeler için üretim ve son kullamım tarihi set etmez. //Çalışma sırasında eksik bir veri ya da işlem hatası oluştuğunda hatayı ekrana mesaj olarak patlatır. İşlemi orada keser. Hata son oluşan fiş kaynaklıdır. //Girişi işlemi yapılan malzemeleri adres Tipi hafif yük rafı tipinde tanımlı adreslere random yerleştirir. BeginForm(GenerateItemsDataForAllAddresses) Warehouse.Get(9) // işlem depo Id si Dikkat ! SysUser'ın bu depoya yetkisi olmalı IF(@@Warehouse="") Set(@RuleErrorMessage,"9 Id li depo tanımı bulunamadı !") Goto(ExitForm) EndIf() //AdressType 2 hafif yük rafı, ilk katlar toplama gözleri olarak kurgulandı malzemeler paletsiz olarak ilk kat gözlerine yerleştirilir. Sql(" select * from sysAddress Where WarehouseId=@@Warehouse.Id and Id not in(29,28) and AddressType=2 Order By Address",@sqlAddressList) If(@sqlAddressList.rowCount=0) Set(@RuleErrorMessage,"@@Warehouse.Code Kodlu depoya ait Hafif Yük Rafı Tipinde adres tanımı bulunamadı !") Goto(ExitForm) EndIf() Set(@SlipId,0) Sql(" select * from OrderSlipLine where SlipType=1 and WarehouseId=@@Warehouse.Id Order by SlipId",@sqlOrderSlipLine) If(@sqlOrderSlipLine="" or @sqlOrderSlipLine.rowCount=0) Set(@RuleErrorMessage,"@@Warehouse.Code Kodlu depoya Satınalma siparişi bulunamadı !") Goto(ExitForm) EndIf() For(@i,1,@sqlOrderSlipLine.rowCount,1) ResetVariables({"name":["@@Warehouse2","@@OrderSlipLine","@@Item","@@ItemVariant","@@ItemUnit"]}) sql(" SELECT FLOOR(RAND(CHECKSUM(NEWID()))*(1-@sqlAddressList.rowCount+1)+@sqlAddressList.rowCount) RndAddressId",@sqlRndAddressId) Set(@rndId,@sqlRndAddressId.rows.1.RndAddressId) Address.Get(@sqlAddressList.rows.@rndId.Id) Set(@Quantity,@sqlOrderSlipLine.rows.@i.Quantity) CustomSlipType.Get(11) //Satınalma İrsaliyesi IF(@@CustomSlipType="") Set(@RuleErrorMessage,"11 Id li İlk Satınalma irsaliyesi kullanıcı tanımlı fiş türü bulunamadı !") Goto(ExitForm) EndIf() Item.Get(@sqlOrderSlipLine.rows.@i.ItemId) If(@@Item!="") ItemUnit.Get(@sqlOrderSlipLine.rows.@i.UnitId) If(@@ItemUnit="") Set(@RuleErrorMessage,"@sqlOrderSlipLine.rows.@i.UnitId Id li birim bulunamadı !") Goto(ExitForm) EndIf() If(@@Item.CanConfigure="1") Item.Get(@sqlOrderSlipLine.rows.@i.VariantId,@@ItemVariant) If(@@ItemVariant="") Set(@RuleErrorMessage,"@sqlOrderSlipLine.rows.@i.VariantId Id li varyant bulunamadı !") Goto(ExitForm) EndIf() EndIf() If(@SlipId!=@sqlOrderSlipLine.rows.@i.SlipId) If(@SlipId>0) CustomSlipType.Get(11) Slip.Generate() If(@Response.Status="-1") Set(@RuleErrorMessage,@Response.Message) Goto(ExitForm) EndIf() EndIf() ResetVariables({"name":["@@OrderSlip","@@OrderSlipLine","@@WorkOrder","@@WorkOrderLine","@@ItemTracking"]}) OrderSlip.Get(@sqlOrderSlipLine.rows.@i.SlipId) WorkOrder.New({"SlipType":"1",},1) If(@Response.Status="-1") Set(@RuleErrorMessage,@Response.Message) Goto(ExitForm) EndIf() Set(@SlipId,@sqlOrderSlipLine.rows.@i.SlipId) EndIf() OrderSlipLine.Get(@sqlOrderSlipLine.rows.@i.Id) If(@@OrderSlipLine="") Set(@RuleErrorMessage,"@sqlOrderSlipLine.rows.@i.Id Id li Sipariş satırı okunamadı !") Goto(ExitForm) EndIf() If(@@Item.TrackingType!=0) ResetVariables({"name":["@trackingNumber","@ProductionDate","@ExpirationDate"]}) Sql(" SELECT FLOOR(RAND(CHECKSUM(NEWID()))*(1-10000000000+1)+10000000000) RndTrackingNumber",@rndTrackingNumber) If(@rndTrackingNumber.rowCount=0) Set(@RuleErrorMessage,"Random Takip Numarası üretilemedi !") Goto(ExitForm) EndIf() Set(@trackingNumber,@rndTrackingNumber.rows.1.RndTrackingNumber) If(@trackingNumber="") Set(@RuleErrorMessage,"Random Takip Numarası üretilemedi (2) !") Goto(ExitForm) EndIf() If(@@Item.TrackingType=1) sql("SELECT CONVERT(date,DATEADD(day, ROUND(DATEDIFF(day, '2019-01-01', '2019-01-01') * RAND(CHECKSUM(NEWID())), 5),DATEADD(second, abs(CHECKSUM(NEWID())) % 9186400,'2019-01-01')),104) ProductionDate",@sqlProductionDate) If(@sqlProductionDate.rowCount=0) Set(@RuleErrorMessage,"Random Üretim tarihi üretilemedi !") Goto(ExitForm) EndIf() Mid(@sqlProductionDate.rows.1.ProductionDate,1,10,@ProductionDate) If(@ProductionDate="") Set(@RuleErrorMessage,"Random Üretim tarihi üretilemedi (2) !") Goto(ExitForm) EndIf() sql("SELECT CONVERT(date,DATEADD(day, ROUND(DATEDIFF(day, '2021-01-01', '2021-01-01') * RAND(CHECKSUM(NEWID())), 5),DATEADD(second, abs(CHECKSUM(NEWID())) % 9186400,'2021-01-01')),104) ExpirationDate",@sqlExpirationDate) If(@sqlExpirationDate.rowCount=0) Set(@RuleErrorMessage,"Random Üretim tarihi üretilemedi !") Goto(ExitForm) EndIf() Mid(@sqlExpirationDate.rows.1.ExpirationDate,1,10,@ExpirationDate) If(@ExpirationDate="") Set(@RuleErrorMessage,"Random Üretim tarihi üretilemedi (2) !") Goto(ExitForm) EndIf() Set(@Condition," and WarehouseId=@@Warehouse.Id and AddressId=@@Address.Id") IF(@@ItemVariant!="") Set(@Condition," and VariantId=@@ItemVariant.Id") EndIf() WorkOrderLine.Get("SlipId=@@WorkOrder.Id and ItemId=@@Item.Id @Condition") If(@@WorkOrderLine="") WorkOrderLine.New({"SlipType":"1","Quantity":"@Quantity"},0) If(@Response.Status="-1") Set(@RuleErrorMessage,@Response.Message) Goto(ExitForm) EndIf() EndIf() ItemTracking.New({"LineType":"4","Quantity":"@Quantity","TrackingNumber":"@trackingNumber","ExpirationDate":"@ExpirationDate","ProductionDate":"@ProductionDate"},1) If(@Response.Status="-1") Set(@RuleErrorMessage,@Response.Message) Goto(ExitForm) EndIf() Else() For(@k,1,@Quantity,1) //Miktar kadar Seri üretilir Set(@Condition," and WarehouseId=@@Warehouse.Id and AddressId=@@Address.Id") IF(@@ItemVariant!="") Set(@Condition," and VariantId=@@ItemVariant.Id") EndIf() WorkOrderLine.Get("SlipId=@@WorkOrder.Id and ItemId=@@Item.Id @Condition") If(@@WorkOrderLine="") WorkOrderLine.New({"SlipType":"1","Quantity":"@Quantity"},0) If(@Response.Status="-1") Set(@RuleErrorMessage,@Response.Message) Goto(ExitForm) EndIf() EndIf() ResetVariables({"name":["@trackingNumber","@ProductionDate","@ExpirationDate"]}) Sql(" SELECT FLOOR(RAND(CHECKSUM(NEWID()))*(1-90009000900+1)+90009000900) RndTrackingNumber",@rndTrackingNumber) If(@rndTrackingNumber.rowCount=0) Set(@RuleErrorMessage,"Random Takip Numarası üretilemedi !") Goto(ExitForm) EndIf() Set(@trackingNumber,@rndTrackingNumber.rows.1.RndTrackingNumber) ItemTracking.New({"LineType":"4","Quantity":"1","TrackingNumber":"@trackingNumber","ExpirationDate":"@ExpirationDate","ProductionDate":"@ProductionDate"},1) If(@Response.Status="-1") Set(@RuleErrorMessage,@Response.Message) Goto(ExitForm) EndIf() Next() EndIf() Else() WorkOrderLine.New({"SlipType":"1","Quantity":"@Quantity"},1) If(@Response.Status="-1") Set(@RuleErrorMessage,@Response.Message) Goto(ExitForm) EndIf() EndIf() Else() Set(@RuleErrorMessage,"@sqlOrderSlipLine.rows.@i.Id Id li siparişteki @sqlOrderSlipLine.rows.@i.ItemId Id li malzeme bulunamadı !") Goto(ExitForm) EndIf() Next() Slip.Generate() Set(@RuleResponse.Status,"0") Goto(SuccsessExitForm) ExitForm: Set(@RuleResponse.Status,@Response.Status) Set(@RuleResponse.CustomMessage,"Hata oluştu : @RuleErrorMessage") Goto(ReturnForm) SuccsessExitForm: If(@RuleResponse.Status="0") Set(@RuleResponse.CustomMessage,"İşlem tamamlandı.") EndIf() ReturnForm: Set(@Response.Message,"") EndForm()