a:19:{i:0;a:7:{s:7:"cod_prj";s:7:"Veratex";s:6:"versao";s:1:"1";s:7:"cod_apl";s:22:"beam_pyalloc_edit_grid";s:4:"nome";s:0:"";s:4:"tipo";s:0:"";s:5:"parms";s:0:"";s:6:"codigo";s:0:"";}i:1;a:7:{s:7:"cod_prj";s:7:"Veratex";s:6:"versao";s:1:"1";s:7:"cod_apl";s:22:"beam_pyalloc_edit_grid";s:4:"nome";s:9:"delRecord";s:4:"tipo";s:1:"M";s:5:"parms";s:0:"";s:6:"codigo";s:543:"//update the package yarn entry for the OLD yarn order
echo [var_yo]; // tested. it's okay and correct
echo "<br>";
sc_lookup(dataset,"SELECT COALESCE(SUM(lbs_warped),0) FROM pyalloc
                   WHERE yarn_order= '[var_yo]'");
$lbswarped = {dataset[0][0]};
sc_exec_sql("UPDATE potemp
             SET lbs_warped = $lbswarped,
                 inventory = COALESCE(lbs_shippe,0)-lbs_warped-COALESCE(lbs_retd,0)-COALESCE(waste,0),
                 tv = inventory*COALESCE(cost_lb,0)
             WHERE p_o_number = '[var_yo]'");";}i:2;a:7:{s:7:"cod_prj";s:7:"Veratex";s:6:"versao";s:1:"1";s:7:"cod_apl";s:22:"beam_pyalloc_edit_grid";s:4:"nome";s:13:"onAfterDelete";s:4:"tipo";s:1:"E";s:5:"parms";s:0:"";s:6:"codigo";s:517:"delRecord();       // updates the package yarn inv for the yarn order of the record that was deleted
updWarpPerc();     // calculates the new warp perc for remaining pyalloc records for that po
updNetLbsWarped(); // calculates the net lbs warped based on the new warp perc
updYarnNetCost();  //calculates the new net yarn cost based on the new warp perc
updAllPkgYarnInvOnPo(); //updates all the pkg yarn inv for the warping order
updMaster();       //updates the master record
sc_redir(beam_pyalloc_edit_grid);";}i:3;a:7:{s:7:"cod_prj";s:7:"Veratex";s:6:"versao";s:1:"1";s:7:"cod_apl";s:22:"beam_pyalloc_edit_grid";s:4:"nome";s:13:"onAfterInsert";s:4:"tipo";s:1:"E";s:5:"parms";s:0:"";s:6:"codigo";s:160:"updLbsWarped();
updWarpPerc();
updNetLbsWarped();
updYarnCost();
updYarnNetCost();
updAllPkgYarnInvOnPo();
updMaster();
sc_redir(beam_pyalloc_edit_grid);";}i:4;a:7:{s:7:"cod_prj";s:7:"Veratex";s:6:"versao";s:1:"1";s:7:"cod_apl";s:22:"beam_pyalloc_edit_grid";s:4:"nome";s:13:"onAfterUpdate";s:4:"tipo";s:1:"E";s:5:"parms";s:0:"";s:6:"codigo";s:160:"updLbsWarped();
updWarpPerc();
updNetLbsWarped();
updYarnCost();
updYarnNetCost();
updMaster();
updAllPkgYarnInvOnPo();
sc_redir(beam_pyalloc_edit_grid);";}i:5;a:7:{s:7:"cod_prj";s:7:"Veratex";s:6:"versao";s:1:"1";s:7:"cod_apl";s:22:"beam_pyalloc_edit_grid";s:4:"nome";s:14:"onBeforeDelete";s:4:"tipo";s:1:"E";s:5:"parms";s:0:"";s:6:"codigo";s:0:"";}i:6;a:7:{s:7:"cod_prj";s:7:"Veratex";s:6:"versao";s:1:"1";s:7:"cod_apl";s:22:"beam_pyalloc_edit_grid";s:4:"nome";s:14:"onBeforeInsert";s:4:"tipo";s:1:"E";s:5:"parms";s:0:"";s:6:"codigo";s:49:"[var_po] = {p_o_number};
[var_yo] ={yarn_order};";}i:7;a:7:{s:7:"cod_prj";s:7:"Veratex";s:6:"versao";s:1:"1";s:7:"cod_apl";s:22:"beam_pyalloc_edit_grid";s:4:"nome";s:14:"onBeforeUpdate";s:4:"tipo";s:1:"E";s:5:"parms";s:0:"";s:6:"codigo";s:49:"[var_po] = {p_o_number};
[var_yo] ={yarn_order};";}i:8;a:7:{s:7:"cod_prj";s:7:"Veratex";s:6:"versao";s:1:"1";s:7:"cod_apl";s:22:"beam_pyalloc_edit_grid";s:4:"nome";s:9:"onLoadAll";s:4:"tipo";s:1:"E";s:5:"parms";s:0:"";s:6:"codigo";s:0:"";}i:9;a:7:{s:7:"cod_prj";s:7:"Veratex";s:6:"versao";s:1:"1";s:7:"cod_apl";s:22:"beam_pyalloc_edit_grid";s:4:"nome";s:8:"onRecord";s:4:"tipo";s:1:"E";s:5:"parms";s:0:"";s:6:"codigo";s:49:"[var_po] = {p_o_number};
[var_yo] ={yarn_order};";}i:10;a:7:{s:7:"cod_prj";s:7:"Veratex";s:6:"versao";s:1:"1";s:7:"cod_apl";s:22:"beam_pyalloc_edit_grid";s:4:"nome";s:10:"onValidate";s:4:"tipo";s:1:"E";s:5:"parms";s:0:"";s:6:"codigo";s:0:"";}i:11;a:7:{s:7:"cod_prj";s:7:"Veratex";s:6:"versao";s:1:"1";s:7:"cod_apl";s:22:"beam_pyalloc_edit_grid";s:4:"nome";s:20:"updAllPkgYarnInvOnPo";s:4:"tipo";s:1:"M";s:5:"parms";s:0:"";s:6:"codigo";s:2330:"// this is really ugly but I can't get sc lookup to work inside a for loop
// so this does 4, one at a time.
sc_lookup(dataset,"SELECT yarn_order FROM pyalloc
                   WHERE P_O_NUMBER = '[var_po]'
                   GROUP BY yarn_order");
$yarnorder0 = {dataset[0][0]};
$yarnorder1 = {dataset[1][0]};
$yarnorder2 = {dataset[2][0]};
$yarnorder3 = {dataset[3][0]};
if (ISSET($yarnorder0)) 
{
echo($yarnorder0);
echo("<br>");
sc_lookup(dt2,"SELECT COALESCE(SUM(lbs_warped),0) FROM pyalloc
               WHERE yarn_order = $yarnorder0");	
$lbswarped = {dt2[0][0]};
sc_exec_sql("UPDATE potemp
             SET lbs_warped = $lbswarped,
                 inventory = COALESCE(lbs_shippe,0)-lbs_warped-COALESCE(lbs_retd,0)-COALESCE(waste,0),
                 tv = inventory*COALESCE(cost_lb,0)
             WHERE p_o_number = $yarnorder0");
}
if (ISSET($yarnorder1))
{
echo($yarnorder1);
echo("<br>");
sc_lookup(dt2,"SELECT COALESCE(SUM(lbs_warped),0) FROM pyalloc
               WHERE yarn_order = $yarnorder1");	
$lbswarped = {dt2[0][0]};
sc_exec_sql("UPDATE potemp
              SET lbs_warped = $lbswarped,
                  inventory = COALESCE(lbs_shippe,0)-lbs_warped-COALESCE(lbs_retd,0)-COALESCE(waste,0),
                  tv = inventory*COALESCE(cost_lb,0)
             WHERE p_o_number = $yarnorder1");
}
if (ISSET($yarnorder2)) 
{
echo($yarnorder2);
echo("<br>");
sc_lookup(dt2,"SELECT COALESCE(SUM(lbs_warped),0) FROM pyalloc
               WHERE yarn_order = $yarnorder2");	
$lbswarped = {dt2[0][0]};
sc_exec_sql("UPDATE potemp
              SET lbs_warped = $lbswarped,
                  inventory = COALESCE(lbs_shippe,0)-lbs_warped-COALESCE(lbs_retd,0)-COALESCE(waste,0),
                  tv = inventory*COALESCE(cost_lb,0)
             WHERE p_o_number = $yarnorder2");
}
if (ISSET($yarnorder3))
{
echo($yarnorder3);
echo("<br>");
sc_lookup(dt2,"SELECT COALESCE(SUM(lbs_warped),0) FROM pyalloc
               WHERE yarn_order = $yarnorder3");	
$lbswarped = {dt2[0][0]};
sc_exec_sql("UPDATE potemp
              SET lbs_warped = $lbswarped,
                  inventory = COALESCE(lbs_shippe,0)-lbs_warped-COALESCE(lbs_retd,0)-COALESCE(waste,0),
                  tv = inventory*COALESCE(cost_lb,0)
             WHERE p_o_number = $yarnorder3");
}
";}i:12;a:7:{s:7:"cod_prj";s:7:"Veratex";s:6:"versao";s:1:"1";s:7:"cod_apl";s:22:"beam_pyalloc_edit_grid";s:4:"nome";s:12:"updLbsWarped";s:4:"tipo";s:1:"M";s:5:"parms";s:0:"";s:6:"codigo";s:255:"sc_lookup(dataset,"SELECT lbs_recd FROM warppo
                   WHERE p_o_number = '[var_po]'");
$lbswarped = {dataset[0][0]};
sc_exec_sql("UPDATE pyalloc
             SET twarp = COALESCE($lbswarped,0)
             WHERE p_o_number = '[var_po]'");";}i:13;a:7:{s:7:"cod_prj";s:7:"Veratex";s:6:"versao";s:1:"1";s:7:"cod_apl";s:22:"beam_pyalloc_edit_grid";s:4:"nome";s:9:"updMaster";s:4:"tipo";s:1:"M";s:5:"parms";s:0:"";s:6:"codigo";s:466:"//UPDATES WARPPO WITH NEW PKG YARN COST 
//BECAUSE YOU CHANGED THE PACKAGE YARN ALLOCATION RECORD
sc_lookup(dataset,"SELECT SUM(net_cost_l) FROM pyalloc WHERE p_o_number = '[var_po]'");
$master_costlby = {dataset[0][0]};
sc_master_value('cost_lb_y', $master_costlby);
sc_exec_sql("UPDATE warppo
         		SET cost_lb_y = COALESCE($master_costlby,0),
					cost_lb_t = cost_lb_y + cost_lb_w,
					tv = cost_lb_t * inventory
		WHERE p_o_number = '[var_po]'");";}i:14;a:7:{s:7:"cod_prj";s:7:"Veratex";s:6:"versao";s:1:"1";s:7:"cod_apl";s:22:"beam_pyalloc_edit_grid";s:4:"nome";s:15:"updNetLbsWarped";s:4:"tipo";s:1:"M";s:5:"parms";s:0:"";s:6:"codigo";s:123:"sc_exec_sql("UPDATE pyalloc
             SET lbs_warped = twarp * warp_perc
             WHERE p_o_number = '[var_po]'");";}i:15;a:7:{s:7:"cod_prj";s:7:"Veratex";s:6:"versao";s:1:"1";s:7:"cod_apl";s:22:"beam_pyalloc_edit_grid";s:4:"nome";s:13:"updPkgYarnInv";s:4:"tipo";s:1:"M";s:5:"parms";s:0:"";s:6:"codigo";s:519:"//UPDATES PACKAGE YARN INVENTORY
//update the package yarn inventory for yarn order var_yo
sc_lookup(dataset,"SELECT COALESCE(SUM(lbs_warped),0) FROM pyalloc
                   WHERE yarn_order= '[var_yo]'");
$lbswarped = {dataset[0][0]};
sc_exec_sql("UPDATE potemp
             SET lbs_warped = $lbswarped,
                 inventory = COALESCE(lbs_shippe,0)-lbs_warped-COALESCE(lbs_retd,0)-COALESCE(waste,0),
                 tv = inventory*COALESCE(cost_lb,0)
             WHERE p_o_number = '[var_yo]'");
";}i:16;a:7:{s:7:"cod_prj";s:7:"Veratex";s:6:"versao";s:1:"1";s:7:"cod_apl";s:22:"beam_pyalloc_edit_grid";s:4:"nome";s:11:"updWarpPerc";s:4:"tipo";s:1:"M";s:5:"parms";s:0:"";s:6:"codigo";s:313:"//UPDATE PROPORTION OF YARN
sc_lookup(dataset,"SELECT SUM(lbs_ordere) FROM pyalloc
                   WHERE p_o_number = '[var_po]'");
$lbsorderedt = {dataset[0][0]};
sc_exec_sql("UPDATE pyalloc
             SET warp_perc = lbs_ordere / COALESCE($lbsorderedt,1)
             WHERE p_o_number = '[var_po]'");";}i:17;a:7:{s:7:"cod_prj";s:7:"Veratex";s:6:"versao";s:1:"1";s:7:"cod_apl";s:22:"beam_pyalloc_edit_grid";s:4:"nome";s:11:"updYarnCost";s:4:"tipo";s:1:"M";s:5:"parms";s:0:"";s:6:"codigo";s:299:"//UPDATES COST FOR PACKAGE YARN ON PYALLOC FROM POTEMP
sc_lookup(dataset,"SELECT cost_lb FROM potemp
                    WHERE p_o_number = '[var_yo]'");
$costlby = {dataset[0][0]};
sc_exec_sql("UPDATE pyalloc
             SET cost_lb_y = $costlby
             WHERE yarn_order = '[var_yo]'");";}i:18;a:7:{s:7:"cod_prj";s:7:"Veratex";s:6:"versao";s:1:"1";s:7:"cod_apl";s:22:"beam_pyalloc_edit_grid";s:4:"nome";s:14:"updYarnNetCost";s:4:"tipo";s:1:"M";s:5:"parms";s:0:"";s:6:"codigo";s:174:"{net_cost_l} = {warp_perc} * {cost_lb_y};
sc_exec_sql("UPDATE pyalloc
             SET net_cost_l = warp_perc * cost_lb_y
             WHERE p_o_number = '[var_po]'");

";}}