Replacing code based on static variables to variable variables.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David

    Replacing code based on static variables to variable variables.

    Can anyone give me some help or tips in converting this code to take 2 variables that will specify the number of Pack
    type lines and the number of Single type lines. We use it to create a web page that allows us to split a garment
    delivery over multiple dates and and to specify the number and size of garments in a pack and the number and size of
    individual garments in the delivery. 3 of each has been enough until now. However we are finding new customers that want
    it spread over as many as 5 to 8 of each type pack and single.

    Everything is stored in an array $RPack.
    Easy to do as i new there were only ever goung to be 6 lines.

    $maxC is the number of colours available (usually 3)
    $maxR is the number of lengths each colour is available (usually 3)
    $maxH is the number of sizes each length is available in. (Between 8 & 14)

    Input() is a function for drawing HTML input boxes of the format

    Input (Size,Value,Cla ss,Name,Maxleng th,Readonly)

    I think what I need is to use variable variables but I am having a hard time getting my head around it so any tips and
    advice would be very gratefully received.

    // Create Data Entry, Boxes for Amt,Qty Total and Date
    for ($z=0; $z<$maxC; $z++){
    for ($y=0; $y<$maxR; $y++){
    //Set Temp variables to 0 or ""
    $ThisColour = "";
    $ThisRange = "";
    $ColourSize="";
    $P_In0="";
    $P_In1="";
    $P_In2="";
    $S_In0="";
    $S_In1="";
    $S_In2="";
    $Total_In="";
    $RatioTotal_In= "";
    $LineAmt0 = 0;
    $LineAmt1 = 0;
    $LineAmt2 = 0;
    $LineAmtS0 = 0;
    $LineAmtS1 = 0;
    $LineAmtS2 = 0;
    $ColourSize = Input(8,$RatioC olours{$z}.' '.$RatioRange{$ y};,formstyle,C olour_Size,10);

    for ($i=0; $i<$maxH; $i++){
    // Check already an entry if so use it, if not add default order line to singles1 and set rest to 0
    if($fldfldMDA== 1){

    $Pack0 = Input(3,$RPack[0]{$i}{$z}{$y},fo rmstyle,Pack0.$ i.$z.$y,10);
    $LineAmt0 = $LineAmt0 + $RPack[0]{$i}{$z}{$y};
    $ColSumP0{$i}{$ z}{$y} = ($RPack[0]{$i}{$z}{$y}*$R Pack[0]{$Qty}{$z}{$y}) ;

    $Pack1 = Input(3,$RPack[1]{$i}{$z}{$y},fo rmstyle,Pack1.$ i.$z.$y,10);
    $LineAmt1 = $LineAmt1 + $RPack[1]{$i}{$z}{$y};
    $ColSumP1{$i}{$ z}{$y} = ($RPack[1]{$i}{$z}{$y}*$R Pack[1]{$Qty}{$z}{$y}) ;

    $Pack2 = Input(3,$RPack[2]{$i}{$z}{$y},fo rmstyle,Pack2.$ i.$z.$y,10);
    $LineAmt2 = $LineAmt2 + $RPack[2]{$i}{$z}{$y};
    $ColSumP2{$i}{$ z}{$y} = ($RPack[2]{$i}{$z}{$y}*$R Pack[2]{$Qty}{$z}{$y}) ;

    $Singles0 = Input(3,$RPack[3]{$i}{$z}{$y},fo rmstyle,Singles 0.$i.$z.$y,10);
    $LineAmtS0 = $LineAmtS0 + $RPack[3]{$i}{$z}{$y};
    $ColSumS0{$i}{$ z}{$y} = ($RPack[3]{$i}{$z}{$y}*$R Pack[3]{$Qty}{$z}{$y}) ;

    $Singles1 = Input(3,$RPack[4]{$i}{$z}{$y},fo rmstyle,Singles 1.$i.$z.$y,10);
    $LineAmtS1 = $LineAmtS1 + $RPack[4]{$i}{$z}{$y};
    $ColSumS1{$i}{$ z}{$y} = ($RPack[4]{$i}{$z}{$y}*$R Pack[4]{$Qty}{$z}{$y}) ;

    $Singles2 = Input(3,$RPack[5]{$i}{$z}{$y},fo rmstyle,Singles 2.$i.$z.$y,10);
    $LineAmtS2 = $LineAmtS2 + $RPack[5]{$i}{$z}{$y};
    $ColSumS2{$i}{$ z}{$y} = ($RPack[5]{$i}{$z}{$y}*$R Pack[5]{$Qty}{$z}{$y}) ;

    $ColTotal =
    $ColSumP0{$i}{$ z}{$y}+$ColSumP 1{$i}{$z}{$y}+$ ColSumP2{$i}{$z }{$y}+$ColSumS0 {$i}{$z}{$y}+$C olSumS1{$i}{$z} {$y}+$ColSumS2{
    $i}{$z}{$y};

    $RatioTotal = Input(3,$ColTot al,formstyle,Co lTotal.$i.$z.$y ,10);

    $Total = Input(3,$RatioA mt{$i}{$z}{$y}, formstyle,Total .$i.$z.$y,10);

    }
    else{
    $Pack0 = Input(3,0,forms tyle,Pack0.$i.$ z.$y,10);
    $Pack1 = Input(3,0,forms tyle,Pack1.$i.$ z.$y,10);
    $Pack2 = Input(3,0,forms tyle,Pack2.$i.$ z.$y,10);
    $Singles0 = Input(3,$RatioA mt{$i}{$z}{$y}, formstyle,Singl es0.$i.$z.$y,10 );
    $Singles1 = Input(3,0,forms tyle,Singles1.$ i.$z.$y,10);
    $Singles2 = Input(3,0,forms tyle,Singles2.$ i.$z.$y,10);
    $Total = Input(3,$RatioA mt{$i}{$z}{$y}, formstyle,Total .$i.$z.$y,10);
    $RatioTotal = Input(3,0,forms tyle,ColTotal.$ i.$z.$y,10);
    }
    //Save Input Boxes for later
    $P_In0 = $P_In0.$Pack0;
    $P_In1 = $P_In1.$Pack1;
    $P_In2 = $P_In2.$Pack2;
    $S_In0 = $S_In0.$Singles 0;
    $S_In1 = $S_In1.$Singles 1;
    $S_In2 = $S_In2.$Singles 2;
    $Total_In = $Total_In.$Tota l;
    $RatioTotal_In = $RatioTotal_In. $RatioTotal;
    }
    $RatioPacksOrde red =
    $ColourSize.'<b r>'.$fldHeaderR .'<br>'.$P_In0. '<br>'.$P_In1.' <br>'.$P_In2.'< br>'.$S_In0.'<b r>'.$S_In1.'<br >'.$S_In2.'<b r>
    '.$RatioTotal_I n.'<br>'.$Total _In.'<br>';
    //Pass to display variable
    $fldfldRatioPac ksOrdered = $fldfldRatioPac ksOrdered.$Rati oPacksOrdered.' <br>';
    }
    }


Working...