/// <summary> /// Allocate cost for selected period /// </summary> /// <param name="pobjObject"></param> /// <param name="pdtbDetail"></param> public void Allocate(object pobjObject, DataTable pdtbDetail) { CST_AllocationResultDS dsAllocationResult = new CST_AllocationResultDS(); CST_ActCostAllocationMasterVO voAllocationMaster = (CST_ActCostAllocationMasterVO)pobjObject; //Delete old data first dsAllocationResult.DeleteByAllocationMasterID(voAllocationMaster.ActCostAllocationMasterID); //copy table DataTable dtbSource = pdtbDetail.Copy(); //Table contain max lead time DataTable dtbLeadTime; dtbLeadTime = dsAllocationResult.GetLeadTimeData(voAllocationMaster.FromDate, voAllocationMaster.ToDate, voAllocationMaster.CCNID); //Table contain completed quantity by production line DataTable dtbCompletedByProductionLine; dtbCompletedByProductionLine = dsAllocationResult.GetCompletedQuantityByProductionLine(voAllocationMaster.FromDate, voAllocationMaster.ToDate, voAllocationMaster.CCNID); //Table contain completed quantity by product DataTable dtbCompletedByProductGroup; dtbCompletedByProductGroup = dsAllocationResult.GetCompletedQuantityByProductGroup(voAllocationMaster.FromDate, voAllocationMaster.ToDate, voAllocationMaster.CCNID); #region Temp table to keep completed quantity, leadtime of product DataTable dtbTemp = new DataTable(); dtbTemp.Columns.Add(CST_AllocationResultTable.PRODUCTID_FLD, typeof(System.Int32)); dtbTemp.Columns.Add(QUANTITY_LEADTIME_FLD, typeof(System.Decimal)); dtbTemp.Columns.Add(COMPLETED_QUANTITY_FLD, typeof(System.Decimal)); #endregion //Build template of AllocationResult table DataTable dtbAllocationResult = BuildAllocationResultTemplate(); //Loop each row and insert data foreach (DataRow drowSource in dtbSource.Rows) { //irnoge deleted row if (drowSource.RowState == DataRowState.Deleted) { continue; } //Processing if product is not null if (!drowSource[CST_ActCostAllocationDetailTable.PRODUCTID_FLD].Equals(DBNull.Value) && drowSource[CST_ActCostAllocationDetailTable.PRODUCTID_FLD].ToString().Trim() != string.Empty) { //Allocate cost by product AllocateByProduct(drowSource, dtbCompletedByProductGroup, dtbAllocationResult); //move to next row continue; } //Processing if product group is not null if (!drowSource[CST_ActCostAllocationDetailTable.PRODUCTGROUPID_FLD].Equals(DBNull.Value) && drowSource[CST_ActCostAllocationDetailTable.PRODUCTGROUPID_FLD].ToString().Trim() != string.Empty) { //Allocate cost by product group AllocateByGroup(drowSource, dtbCompletedByProductGroup, dtbLeadTime, dtbTemp, dtbAllocationResult); //move to next row continue; } //Processing if production line is not null if (!drowSource[CST_ActCostAllocationDetailTable.PRODUCTIONLINEID_FLD].Equals(DBNull.Value) && drowSource[CST_ActCostAllocationDetailTable.PRODUCTIONLINEID_FLD].ToString().Trim() != string.Empty) { //Allocate cost by production line AllocateByProductionLine(drowSource, dtbCompletedByProductionLine, dtbLeadTime, dtbTemp, dtbAllocationResult); //move to next row continue; } //Processing if deparment is not null if (!drowSource[CST_ActCostAllocationDetailTable.DEPARTMENTID_FLD].Equals(DBNull.Value) && drowSource[CST_ActCostAllocationDetailTable.DEPARTMENTID_FLD].ToString().Trim() != string.Empty) { //Allocate cost by department AllocateByDepartment(drowSource, dtbCompletedByProductionLine, dtbLeadTime, dtbTemp, dtbAllocationResult); //move to next row continue; } //Finally, allocate cost by CCN AllocateByCCN(voAllocationMaster.CCNID, drowSource, dtbCompletedByProductionLine, dtbLeadTime, dtbTemp, dtbAllocationResult); } //foreach //Build dataset for allocation result DataSet dtsAllocation = dtbAllocationResult.DataSet; if (dtsAllocation == null) { dtsAllocation = new DataSet(); dtsAllocation.Tables.Add(dtbAllocationResult); } //update dataset dsAllocationResult.UpdateDataSet(dtsAllocation); dsAllocationResult.InsertNewAllocation(voAllocationMaster.ActCostAllocationMasterID, voAllocationMaster.FromDate, voAllocationMaster.ToDate); }
/// <summary> /// Gets allocation amount of period /// </summary> /// <param name="pintPeriodID">Period</param> /// <returns>Allocation Amount</returns> public DataTable GetAllocationAmount(int pintPeriodID) { CST_AllocationResultDS dsAllocation = new CST_AllocationResultDS(); return(dsAllocation.List(pintPeriodID)); }