public async Task <ActionResult> Go(InitiateTabletisingCommandViewModel item) { var result = await _createTabletisingCommandDomain.InitiateTabletisingCommand(item); return(Json(new { result })); }
/// <summary> /// This function is for saving production planing. /// </summary> public async Task <InitiateTabletisingCommandResult> InitiateTabletisingCommand(InitiateTabletisingCommandViewModel item) { #region Command validation //• If [f41_status] is not “3” in database and [f41_kndcmdno] = [Kneading No.] and [f41_prepdtlotno] = [Lot No.] on the table on “List of Kneading Command” section, the system will show message as MSG 16. var tabletCommands = _unitOfWork.TabletCommandRepository.GetAll(); tabletCommands = tabletCommands.Where(x => !x.F41_Status.Trim().Equals(Constants.F41_Status.NotTablet)); tabletCommands = tabletCommands.Where(x => x.F41_KndCmdNo.Trim().Equals(item.KneadingNo.Trim())); tabletCommands = tabletCommands.Where(x => x.F41_PrePdtLotNo.Trim().Equals(item.LotNo.Trim())); //if (await tabletCommands.AnyAsync()) // return "MSG16"; if (await tabletCommands.AnyAsync()) { return(InitiateTabletisingCommandResult.CommandExist); } #endregion var lotNo = item.LotNo; var kneadingCommand = _unitOfWork.KneadingCommandRepository.Get( i => i.F42_KndCmdNo.Trim().Equals(item.KneadingNo.Trim())); var tblCntAmt = kneadingCommand.F42_StgCtnAmt; // Delete the record from “tx56_tbtpdt” table in database where [f56_kndcmdno] = [Kneading No.] column of table on “List of Kneading Command” section and [f56_prepdtlotno] = [Lot No.] column of table on “List of Kneading Command” section _unitOfWork.TabletProductRepository.Delete( x => x.F56_KndCmdNo.Trim().Equals(item.KneadingNo.Trim()) && x.F56_PrePdtLotNo.Trim().Equals(lotNo.Trim())); //o If the system delete record successfully, //the system will continue deleting record from “tx41_tbtcmd” in database where [f41_kndcmdno] = [Kneading No.] column on //table on “List of Kneading Command” section and [f41_prepdtlotno] = [Lot No.] column on table on “List of Kneading Command” section _unitOfWork.TabletCommandRepository.Delete( x => x.F41_KndCmdNo.Trim().Equals(item.KneadingNo.Trim()) && x.F41_PrePdtLotNo.Trim().Equals(lotNo.Trim())); /* * If the system delete record from “tx56_tbtpdt” table and “tx41_tbtcmd” table successfully, the system will perform the following actions: * o Insert new record into the “tx41_tbtcmd” table as below: * • [f41_ kndcmdno] = [Kneading No.] column of table on “List of Kneading Command” section. * • [f41_prepdtlotno] = [Lot No.] column of table on “List of Kneading Command” section. * • [f41_preproductcode] = [Pre-Product Code] column of table on “List of Kneading Command” section. * • [f41_status] = “3” (Not Tablet) * • [f41_tblcntamt] = [f42_ stgctnamt] where [f42_ kndcmdno] = [Kneading No.] column of table on “List of Kneading Command” section and [f42_preproductcode] = [Pre-Product Code] column on table on “List of Kneading Command” section * • [f41_rtrendcntamt] = “0”. * • [f41_chgcntamt] = “0”. * • [f41_adddate] = current date (format DD/MM/YYYY hh:mm:ss). * • [f41_updatedate] = current date (format DD/MM/YYYY hh:mm:ss). * • [f41_updatecount] = “0” */ var systemTime = DateTime.Now; var tabletCommand = new TX41_TbtCmd(); tabletCommand.F41_KndCmdNo = item.KneadingNo; tabletCommand.F41_PrePdtLotNo = lotNo; tabletCommand.F41_PreproductCode = item.PreproductCode; tabletCommand.F41_Status = Constants.F41_Status.NotTablet; tabletCommand.F41_TblCntAmt = tblCntAmt; tabletCommand.F41_RtrEndCntAmt = 0; tabletCommand.F41_ChgCntAmt = 0; tabletCommand.F41_AddDate = systemTime; tabletCommand.F41_UpdateDate = systemTime; tabletCommand.F41_UpdateCount = 0; _unitOfWork.TabletCommandRepository.Add(tabletCommand); // Find all kneading commands in database. var kneadingCommands = _unitOfWork.KneadingCommandRepository.GetAll(); kneadingCommands = kneadingCommands.Where( x => x.F42_KndCmdNo.Trim().Equals(item.KneadingNo.Trim()) && x.F42_PrePdtLotNo.Trim().Equals(item.LotNo.Trim())); foreach (var command in kneadingCommands) { command.F42_Status = Constants.F42_Status.TX42_Sts_Tbtcmd; _unitOfWork.KneadingCommandRepository.Update(command); } /* * o If the system insert new record into “tx41_tbtcmd” table in database successfully, the system will insert all the records of the lower table on Screen 2 into “tx56_tbtpdt” table in database, each record contains the data as follow: * • [f56_kndcmdno] = [Kneading No.] column of table on “List of Kneading Command” section. * • [f56_prepdtlotno] = [Lot No.] column of table on “List of Kneading Command” section. * • [f56_productcode] = [Product Code] column of the lower table on “Create Tabletising Command” form. * • [f56_productlotno] = [Lot No.] column of the lower table on “Create Tabletising Command” form. * • [f56_status] = “Yet”. * • [f56_tbtcmdamt] = [Tablet Qty] column on the lower table on “Create Tabletising Command” form. * • [f56_tbtcmdendpackamt] = 0.0 * • [f56_tbtcmdendfrtamt] = 0.0 * • [f56_tbtcmdendamt] = 0.0 * • [f56_storageamt] = 0.0 * • [f56_certificationflag] = * • [f56_adddate] = current date (format DD/MM/YYYY hh:mm:ss). * • [f56_updatedate] = current date (format DD/MM/YYYY hh:mm:ss). * • [f56_updatecount] = 0. */ if (item.Items != null) { foreach (var lowerItem in item.Items) { var tabletProduct = new TX56_TbtPdt(); tabletProduct.F56_KndCmdNo = item.KneadingNo; tabletProduct.F56_PrePdtLotNo = lotNo; tabletProduct.F56_ProductCode = lowerItem.ProductCode; tabletProduct.F56_ProductLotNo = lowerItem.LotNo; tabletProduct.F56_CertificationFlag = Constants.F56_Status.NotTablet; tabletProduct.F56_Status = Constants.F56_Status.NotTablet; tabletProduct.F56_TbtCmdAmt = lowerItem.TabletisingQuantity; tabletProduct.F56_TbtCmdEndPackAmt = 0; tabletProduct.F56_TbtCmdEndFrtAmt = 0; tabletProduct.F56_TbtCmdEndAmt = 0; tabletProduct.F56_StorageAmt = 0; tabletProduct.F56_AddDate = systemTime; tabletProduct.F56_UpdateDate = systemTime; _unitOfWork.TabletProductRepository.Add(tabletProduct); } } // Commit the changes. await _unitOfWork.CommitAsync(); return(InitiateTabletisingCommandResult.Success); }