<?php

require("deps.php");
require_once("common.php");

$pcwo = $_REQUEST['pcwo'];

echo "<br>";
echo "<table width=100%><tr><td width=64% valign=top>";

echo "<table class=moneylist><tr><th>".pcrtlang("Add Labor")."</th></tr><tr><td>";
echo "<form action=repcart.php?func=add_labor2 method=post><input type=hidden name=pcwo value=$pcwo>";
echo "<span class=\"boldme\">".pcrtlang("Qty")."</span><input type=number class=textboxw name=qty value=1 min=\".01\" step=\".01\" style=\"width:40px;\">";
echo "<input type=text class=textboxw size=40 name=labordesc placeholder=\"".pcrtlang("Enter Labor Title")."\"> <span class=\"boldme\">$money</span><input type=text class=textboxw size=6 name=laborprice id=laborprice required=required onFocus=\"this.form.submitbutton.disabled=false;this.form.submitbutton.value='&laquo;".pcrtlang("Add Labor")."';\">";

$usertaxid = getusertaxid();
$servicetaxrateremain = (1 + getservicetaxrate($usertaxid));
if($servicetaxrateremain != 1) {
echo "<button class=button type=button title=\"".pcrtlang("Pre-Tax Calculator")."\" onclick='document.getElementById(\"laborprice\").value=(document.getElementById(\"laborprice\").value / $servicetaxrateremain).toFixed(5)'>
<i class=\"fa fa-calculator\"></i></button>";
}

echo "<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<textarea class=textboxw cols=55 rows=1 name=laborpdesc placeholder=\"".pcrtlang("Enter Optional Printed Labor Description")."\"></textarea>";
echo "<button type=button class=button id=submitbutton onclick=\"this.disabled=true; this.form.submit();\" style=\"float:right;\"><i class=\"fa fa-arrow-circle-right\"></i> <i class=\"fa fa-shopping-cart\"></i></button></form>";
echo "</td></tr></table><br>";

echo "<table class=moneylist><tr><th>".pcrtlang("Add Items from Inventory")."</th></tr><tr><td>";
echo "<form action=repcart.php?func=add_item method=post><input type=hidden name=pcwo value=$pcwo>";
echo "<span class=\"boldme\">".pcrtlang("Qty")."</span><input type=number class=textboxw name=qty value=1 min=1 step=1 style=\"width:40px;\">";
echo "<input type=text class=textboxw size=45 autocomplete=off id=autoinvsearchbox name=\"stockid\" placeholder=\"".pcrtlang("Enter Stock Id Numbers or Search Term")."\">";
echo "<button type=submit class=button style=\"float:right;\"><i class=\"fa fa-arrow-circle-right\"></i> <i class=\"fa fa-shopping-cart\"></i></button></form>";
echo "<div id=\"autoinvsearch\"></div>";
echo "</td></tr></table><br>";

echo "<form action=repcart.php?func=add_noninv name=add_noninv id=add_noninv method=post>";
echo "<table class=moneylist><tr><th>".pcrtlang("Add Non Inventoried Item")."</th></tr><tr><td>";
echo "<span class=\"boldme\">".pcrtlang("Qty")."</span><input type=number class=textboxw name=qty value=1 min=1 step=1 style=\"width:40px;\">";
echo "<input type=text class=textboxw size=50 name=itemdesc placeholder=\"".pcrtlang("Enter Item Name")."\"></td></tr>";

echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<textarea class=textboxw cols=53 name=itempdesc placeholder=\"".pcrtlang("Enter Optional Printed Item Description")."\"></textarea></td></tr>";

echo "<tr><td><span class=\"boldme\">&nbsp;".pcrtlang("Serial/Code").":&nbsp;</span><span class=\"sizemesmaller italme\">(".pcrtlang("optional").")</span>
<input type=text class=textboxw name=itemserial size=35></td></tr><tr><td>";


echo "<span class=\"boldme\">&nbsp;".pcrtlang("Price")."&nbsp;$money</span><input type=text class=textboxw name=itemprice id=itemprice size=5 required=required>";

$usertaxid = getusertaxid();
$salestaxrateremain = (1 + getsalestaxrate($usertaxid));
if($salestaxrateremain != 1) {
echo "<button class=button type=button title=\"".pcrtlang("Pre-Tax Calculator")."\" onclick='document.getElementById(\"itemprice\").value=(document.getElementById(\"itemprice\").value / $salestaxrateremain).toFixed(5)'>
<i class=\"fa fa-calculator\"></i></button>";
}

echo "<span class=\"boldme\">&nbsp;".pcrtlang("Cost")."&nbsp;$money</span>";
echo "<input type=text class=textboxw name=ourprice size=4 value=\"0.00\"><input type=hidden name=woid value=$pcwo>";

?>
<script>
function markup() {
var marknum = Math.ceil((document.add_noninv.ourprice.value - 0) * (document.add_noninv.chooser.value - 0)) - document.add_noninv.cents.value;
document.add_noninv.itemprice.value = marknum.toFixed(2);
}
</script>



<script type="text/javascript">
$(document).ready(function(){
  $("input#autoinvsearchbox").keyup(function(){
    if(this.value.length<3) {
      $("div#autoinvsearch").slideUp(200,function(){
        return false;
      });
    }else{
        var encodedinv = encodeURIComponent(this.value);
        $('div#autoinvsearch').load('autosearch.php?func=inv&search='+encodedinv).slideDown(200);
    }
  });
});
</script>

<?php

echo "<span class=\"boldme\">".pcrtlang("Markup").": </span>";
echo "<select name=chooser class=select onChange=\"markup()\">
<option value=\"1.0\"></option>
<option value=\"1.04\">4%</option>
<option value=\"1.1\">10%</option>
<option value=\"1.2\">20%</option>
<option value=\"1.3\">30%</option>
<option value=\"1.4\">40%</option>
<option value=\"1.5\">50%</option>
<option value=\"1.75\">75%</option>
<option value=\"2\">2X</option>
<option value=\"3\">3X</option>
<option value=\"5\">5X</option>
<option value=\"10\">10X</option>
</select>";

echo "<select name=cents onChange=\"markup()\">
<option value=\"0.10\">90 cents</option>
<option value=\"0.05\">95 cents</option>
<option value=\"0.01\">99 cents</option>
<option value=\"00\">00 cents</option>
</select>";


echo "<button type=submit class=button id=submitbutton style=\"float:right;\"><i class=\"fa fa-arrow-circle-right\"></i> <i class=\"fa fa-shopping-cart\"></i></button>";
echo "</td></tr></table></form>";


echo "<br><table class=moneylist><tr><th>".pcrtlang("Special Order Parts")."</th></tr><tr><td>";
echo "<button onClick=\"parent.location='pc.php?func=addspo&woid=$pcwo'\" class=button>".pcrtlang("Add Special Order Part")."</button>";
echo "</td></tr></table><br>";

echo "<table class=moneylist><tr><th>".pcrtlang("Add Kit to Repair Cart")."</th></tr><tr><td>";
echo "<form action=\"../store/cart.php?func=copysavecart\" method=post><input type=hidden name=pcwo value=$pcwo><select name=cartname>";
$rs_find_cart_items = "SELECT DISTINCT cartname, savedwhen FROM savedcarts WHERE iskit = '1' ORDER BY cartname ASC";
$rs_result = mysqli_query($rs_connect, $rs_find_cart_items);
while($rs_result_q = mysqli_fetch_object($rs_result)) {
$rs_cart_name = "$rs_result_q->cartname";
$rs_saved_when = "$rs_result_q->savedwhen";


echo "<option value=\"$rs_cart_name\">$rs_cart_name</option>";
}
echo "</select>";

echo "<button type=button class=button onclick=\"this.disabled=true;this.value='".pcrtlang("Adding Kit")."...'; this.form.submit();\"><i class=\"fa fa-plus\"></i> ".pcrtlang("Add Kit to Repair Cart")."</button></form>";

echo "</td></tr></table>";

echo "</td><td width=2%>&nbsp;</td><td width=36% valign=top>";

echo "<table class=moneylist><tr><th colspan=2>".pcrtlang("Add Quick Labor")."</th></tr>";
$rs_quicklabor = "SELECT * FROM quicklabor ORDER BY theorder DESC";
$rs_result_ql  = mysqli_query($rs_connect, $rs_quicklabor);

$qlimit = 20;

$quickcount = mysqli_num_rows($rs_result_ql);
if($quickcount > $qlimit) {
echo "<tr><td colspan=2><form action=\"repcart.php?func=add_labor3\" method=post><input type=hidden name=pcwo value=$pcwo><select name=qlid onchange='this.form.submit()'>";
echo "<option value=\"0\">".pcrtlang("Choose").":</option>";
}

while($rs_result_qld = mysqli_fetch_object($rs_result_ql)) {
$labordesc = "$rs_result_qld->labordesc";
$printdesc = "$rs_result_qld->printdesc";
$laborprice = mf("$rs_result_qld->laborprice");
$qlid = "$rs_result_qld->quickid";

$labordesc2 = urlencode("$labordesc");
$printdesc2 = urlencode("$printdesc");

$primero = substr("$labordesc", 0, 1);
if($quickcount <= $qlimit) {
if("$primero" != "-") {
echo "<tr><td style=\"text-align:right; padding:2px;\"><a href=\"repcart.php?func=add_labor2&labordesc=$labordesc2&pcwo=$pcwo&laborprice=$laborprice&laborpdesc=$printdesc2\" class=\"linkbuttonsmall linkbuttonmoney radiusall displayblock\">$money$laborprice</a></td><td><span class=\"boldme\">$labordesc</span></td></tr>";
} else {
$labordesc3 = substr("$labordesc", 1);
echo "<tr><td colspan=2 style=\"vertical-align:bottom\"><span class=\"linkbuttonsmall linkbuttonmoneylabel displayblock radiusall\">$labordesc3</span></td></tr>";
}

} else {
if("$primero" != "-") {
echo "<option value=\"$qlid\">$money$laborprice $labordesc</option>";
} else {
$labordesc3 = substr("$labordesc", 1);
echo "<option value=\"0\" style=\"background:#4D5434;color:#ffffff;padding:3px;\">$labordesc3</option>";
}
}


}

if($quickcount > $qlimit) {
echo "</select></form></td></tr>";
}


echo "</table>";

echo "<br><a href=\"repcart.php?func=add_labor2&labordesc=NO%20CHARGE&pcwo=$pcwo&laborprice=0&laborpdesc=\" class=\"linkbuttonmedium linkbuttonmoney displayblock radiusall\"><i class=\"fa fa-ban fa-lg\"></i> ".pcrtlang("NO CHARGE")."</a><br>";



echo "</td></tr></table>";
stop_box();

?>


