コード例 #1
0
<?php

include "IMSEmail.php";
$Supplier_Part_Number = "R2D2";
$Item_Link = "www.emailtest.com";
$Quantity = "42";
$statusCode = 0;
try {
    $IMSEmail = new IMSEmail();
    $IMSEmail->add_email($Supplier_Part_Number, $Item_Link, $Quantity);
    $statusCode = 1;
} catch (Exception $e) {
    echo "Exception thrown with {$e}";
}
if ($statusCode == 1) {
    echo "Success!";
}
コード例 #2
0
 public function checkThresholds()
 {
     $email = new IMSEmail();
     $cmd0 = "SELECT Value from dbo.Options WHERE [Option]='Thresholds_Enabled'";
     $cmd = 'SELECT * FROM dbo.Inventory';
     $cmd1 = "SELECT Part, Quantity FROM dbo.Class_Data";
     $cmd2 = "SELECT * FROM dbo.Purchase_List";
     $belowCount = 0;
     $aboveCount = 0;
     //Get purchase table data and update inventory table
     foreach ($this->conn->query($cmd1) as $row1) {
         $Name1 = $row1['Part'];
         $Quantity1 = $row1['Quantity'];
         $stmt = $this->conn->prepare("UPDATE dbo.Inventory SET Lab_Quantity={$Quantity1} WHERE Name='{$Name1}'");
         $stmt->execute();
     }
     /*
      * If thresholds are disabled this block will execute fully.
      * email list will not get updated but it will still check for items that have been replenished
      */
     foreach ($this->conn->query($cmd0) as $row0) {
         if ($row0['Value'] == "False" || $row0['Value'] == "false") {
             foreach ($this->conn->query($cmd) as $row) {
                 $difference = $row['Quantity'] - $row['Lab_Quantity'];
                 if ($row['Quantity'] >= $row['Ordering_Threshold'] && $row['Threshold_Reported'] == 1 && $difference >= $row['Ordering_Threshold']) {
                     $Name = $row['Name'];
                     $stmt = $this->conn->prepare("UPDATE dbo.Inventory SET Threshold_Reported=0 WHERE Name='{$Name}'");
                     $stmt->execute();
                     $aboveCount++;
                 }
             }
             $message[0] = "Threshold checking is not enabled in options";
             $message[1] = "Number of items restocked above threshold: {$aboveCount}";
             return $message;
         }
     }
     /*
      * If thresholds are enabled this block will execute fully.
      * Items under threshold are added to email list and will check for items that have been replenished
      */
     foreach ($this->conn->query($cmd) as $row) {
         $Name = $row['Name'];
         $difference = $row['Quantity'] - $row['Lab_Quantity'];
         //Check for normal violations
         if ($row['Quantity'] < $row['Ordering_Threshold'] && $row['Threshold_Reported'] == 0) {
             $email->add_email($row['Supplier_Part_Number'], $row['Item_Link'], $row['Quantity'], $row['Ordering_Threshold']);
             $stmt = $this->conn->prepare("UPDATE dbo.Inventory SET Threshold_Reported=1 WHERE Name='{$Name}'");
             $stmt->execute();
             $belowCount++;
         }
         //Offset quantity by lab equipment requirements and see if it violates the threshold
         if ($row['Lab_Part_Flag'] == 1 && $row['Quantity'] >= $row['Ordering_Threshold'] && $row['Threshold_Reported'] == 0) {
             if ($difference < $row['Ordering_Threshold']) {
                 $email->add_email($row['Supplier_Part_Number'], $row['Item_Link'], $row['Quantity'], $row['Ordering_Threshold']);
                 $stmt = $this->conn->prepare("UPDATE dbo.Inventory SET Threshold_Reported=1 WHERE Name='{$Name}'");
                 $stmt->execute();
                 $belowCount++;
             }
         }
         //Check for replenished quantities and remove the threshold violation flag
         if ($row['Quantity'] >= $row['Ordering_Threshold'] && $row['Threshold_Reported'] == 1 && $difference >= $row['Ordering_Threshold']) {
             $Name = $row['Name'];
             $stmt = $this->conn->prepare("UPDATE dbo.Inventory SET Threshold_Reported=0 WHERE Name='{$Name}'");
             $stmt->execute();
             $aboveCount++;
         }
     }
     //Check for entries on the Purchase List table that haven't been reported
     //No check is required for replenished quantities as it's assumed the user will delete
     //the item from the manual entry table
     foreach ($this->conn->query($cmd2) as $row2) {
         if ($row2['Threshold_Reported'] == 0) {
             $Name = $row2['Supplier_Part_Number'];
             $email->add_email($row2['Supplier_Part_Number'], $row2['Item_Link'], $row2['Quantity'], "Manual addition");
             $stmt = $this->conn->prepare("UPDATE dbo.Purchase_List SET Threshold_Reported=1 WHERE Supplier_Part_Number='{$Name}'");
             $stmt->execute();
             $belowCount++;
         }
     }
     $message[0] = "Number of entries added to list: {$belowCount}";
     $message[1] = "Number of items restocked above threshold: {$aboveCount}";
     if ($email->emailNeedsToBeSent()) {
         $recipients = $this->getEmailList();
         $credentials = $this->getEmailCredentials();
         $title = "IMS Low Stock Notification";
         $message[2] = $email->sendEmail($recipients, $title, $credentials);
     }
     return $message;
 }