public function createAddPart()
 {
     if (isset($_POST['itemid']) && !empty($_POST['wid'])) {
         $worksheet = Worksheet::find_by_id($_POST['wid']);
         $myItem = Items::find_by_id($_POST['itemid']);
         $propart = new Prodpart();
         $propart->part_name = $myItem->item_name;
         $propart->qty = $_POST['qty'];
         $propart->works_id = $_POST['wid'];
         $propart->prod_id = $worksheet->prod_id;
         $propart->item_id = $_POST['itemid'];
         $propart->date_changed = date("Y:m:d H:i:s");
         $propart->desc = "";
         $propart->unit_cost = $_POST['price'];
         $propart->total_cost = (int) $_POST['price'] * (int) $_POST['qty'];
         if ($propart->create()) {
             return $propart;
         } else {
             return false;
         }
     }
 }
 public function createAddPart()
 {
     if (isset($_REQUEST['itemid']) && !empty($_REQUEST['wid'])) {
         $worksheet = Worksheet::find_by_id($_REQUEST['wid']);
         $myItem = Items::find_by_id($_REQUEST['itemid']);
         $propart = new Prodpart();
         $propart->part_name = $myItem->item_name;
         $propart->qty = $_REQUEST['qty'];
         $propart->works_id = $_REQUEST['wid'];
         $propart->prod_id = $worksheet->prod_id;
         $propart->item_id = $_REQUEST['itemid'];
         $propart->datecreated = date("Y:m:d H:i:s");
         $propart->des = "";
         $propart->unit_cost = $_REQUEST['price'];
         $propart->total_cost = (int) $_REQUEST['price'] * (int) $_REQUEST['qty'];
         $Tlog = new Transaction();
         $Tlog->com_id = $myItem->item_id;
         $Tlog->trans_type = "WORKSHEET PART SUPPLY";
         $Tlog->trans_description = "allocation of resources to worksheet";
         $Tlog->datecreated = date("Y-m-d H:i:s");
         $Tlog->user_id = $_SESSION['emp_ident'];
         if ($propart->create()) {
             $Tlog->create();
             return $propart;
         } else {
             return false;
         }
     }
 }
 /**
  * cart model to maitain items array
  * in cart befor it is been posted to 
  * the purchases table
  */
 public function doAddToCart()
 {
     $basket = new Cart();
     $mcart = "";
     $basket->addItem($_POST['ppid'], $_POST['ppname'], $_POST['pcatname'], $_POST['pqty'], $_POST['pprice']);
     $myItems = $basket->getContents();
     // the basket get arrays of items in the cart
     $quantity = $_POST['pqty'];
     $subTotal = $basket->getTotal();
     // the basket gets the total of the items as subtotal
     $vat = 0.05 * $subTotal;
     // calculates the vat
     $total = $subTotal + $vat;
     $mcart .= "<table id='minicart-a' summary='Employee Pay Sheet'>\n    <thead>\n    \t<tr>\n            <th width='10%' scope='col'>ItemID</th>\n        \t<th width='35%' scope='col' >Description</th>\n            <th width='20%' scope='col'>Qty</th>\n            <th width='10%' scope='col'>Cost</th>\n            <th width='10%' scope='col'>Total</th>\n            \n        </tr>\n    </thead>\n    <tbody>";
     //print_r($item['itemName']);
     $qt = 0;
     foreach ($myItems as $item) {
         $myproduct = Items::find_by_id($item['itemId']);
         //print_r($myproduct);
         $mcart .= "<tr>\n              \n              <td>" . $item['itemName'] . "</td>\n              <td>" . $myproduct->item_description . "</td>\n              <td><span>\n                <input type='text' name='qty' id='qty" . $qt . "' value='" . $item['itemQuantity'] . "' style='width:40px; padding:2px; height:36px; text-align:center; '  />\n              </span>&nbsp;&nbsp;<span><a href='#' class='modifyqty' prodid='" . $item['itemId'] . "' prodqty='" . $item['itemQuantity'] . "'  tprice='" . $item['itemPrice'] . "' count ='" . $qt . "' ><img src='public/icons/Refresh16.png' width='18' height='18' /></a></span>&nbsp;&nbsp;<span><a href='#' class='deleteitem' prodid='" . $item['itemId'] . "'  ><img src='public/icons/Delete16.png' width='18' height='18' /></a></span></td>\n              <td>&#8358;" . number_format($item['itemPrice'], 2, '.', ',') . "</td>\n              <td>&#8358;" . number_format($item['itemTotal'], 2, '.', ',') . "</td>\n            </tr>";
         $qt++;
     }
     /**
      * foreach($myItems as $item){
      *     	$mcart .="<tr>
      *         	<td>".$item['itemQuantity']."</td>
      *             <td>".$item['itemName']."</td>
      *             <td>&#8358;".$item['itemName']."</td>
      *             <td>".number_format($item['itemPrice'],2,'.',',')."</td>
      *             <td><span class='bold'>&#8358;".number_format($item['itemTotal'],2,'.',',')."</span></td>
      *             <td><span class='bold'>x</span></td>
      *         </tr>
      *         
      *         ";
      * 	}
      */
     $mcart .= "<tr>\n        \t<td>&nbsp;</td>\n            <td>&nbsp;</td>\n            <td>&nbsp;</td>\n            <td>&nbsp;</td>\n            <td>&nbsp;</td>\n        </tr>       \n\t    <tr>\n          <td>&nbsp;</td>\n          <td colspan='3' align='right'><h3 class='black'>SubTotal:</h3></td>\n          <td colspan='3' align='right'><span class='bold'>&#8358;" . number_format($subTotal, 2, '.', ',') . "</span></td>\n        </tr>\n        <tr>\n          <td>&nbsp;</td>\n          <td colspan='3' align='right'><h3 class='black'>VAT(5%):</h3></td>\n          <td colspan='3' align='right'><span class='bold'>&#8358;" . number_format($vat, 2, '.', ',') . "</span></td>\n        </tr>\n        <tr>\n          <td>&nbsp;</td>\n          <td colspan='3' align='right'><h3><span class='black'>Total:</span></h3></td>\n          <td colspan='3' align='right'><div class='divider'></div><h3 class='bold'>&#8358;" . number_format($total, 2, '.', ',') . "</h3><div class='divider'></div><div class='divider'></div></td>\n        </tr>\n        <tr>\n        \t<td>&nbsp;</td>\n            <td colspan='3' align='right'><span style='margin:5px'><a href='#'>view cart</a></span></td>\n            <td colspan='3'><span style='margin:5px'><a href='#'>Check out</a></span></td>\n            </tr>\n    </tbody>\n</table>";
     print_r($mcart);
 }
 public function delete($id)
 {
     $article = Items::find_by_id($id);
     if ($article->delete()) {
         return true;
     }
 }