PageRenderTime 80ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/manager/auth/order/quotation/generate.php

https://bitbucket.org/nav_subhamkumar/crm
PHP | 297 lines | 163 code | 97 blank | 37 comment | 19 complexity | 1c08e0a394f27eca62d2f46d2c83f32f MD5 | raw file
Possible License(s): Unlicense, GPL-2.0, GPL-3.0
  1. <?php
  2. session_start();
  3. error_reporting(E_PARSE | E_ERROR);
  4. $id=$_SESSION['id'];
  5. if(!$_SESSION['id'])
  6. {
  7. echo '<script>location.replace("../../../../../index.php");</script>';
  8. }
  9. require_once "../../../conn/conn.php";
  10. $chk=mysqli_query($dbc,"select * from team where email='$id'");
  11. while($fchk=mysqli_fetch_assoc($chk))
  12. {
  13. $type=$fchk['EmployeeType'];
  14. if( $type !="Manager")
  15. {
  16. echo '<script>location.replace("../../../../index.php");</script>';
  17. }
  18. }
  19. ?>
  20. <?php
  21. if(isset($_POST['submit']))
  22. {
  23. $rep=$_SESSION['n'];
  24. $rmail=$id;
  25. $company=$_POST['company'];
  26. /*$array = explode('.', $companywfid);
  27. $fid=$array[0];
  28. $company=$array[1];*/
  29. $quotationnumber=$_POST['quotationnumber'];
  30. $_SESSION['quotationnumber']=$quotationnumber;
  31. $revisedno=$_POST['revisedno'];
  32. $currency=$_POST['currency'];
  33. $validity=$_POST['validity'];
  34. $delivery=$_POST['delivery'];
  35. $service=$_POST['service'];
  36. $payment=$_POST['payment'];
  37. $servicename=$_POST['servicename'];
  38. $servicecost=$_POST['servicecost'];
  39. $servicetax=$_POST['servicetax'];
  40. $freightname=$_POST['freightname'];
  41. $freightcost=$_POST['freightcost'];
  42. $freighttax=$_POST['freighttax'];
  43. $expectedclosure=$_POST['expectedclosure'];
  44. $addreq=$_POST['addreq'];
  45. $quotformname=$_POST['quotformname'];
  46. $remarks=$_POST['remarks'];
  47. /*for($m=0;$m<=3;$m++)
  48. {
  49. for($l=0;$l<=3;$l++)
  50. {
  51. echo $tax=$_POST['tax'];
  52. }
  53. }*/
  54. $tax=implode(",",$_POST['tax']);
  55. $_SESSION['fid']=null;
  56. $_SESSION['fid']=$fid;
  57. $_SESSION['qcompany']=$company;
  58. /*$_SESSION['qproduct']=$product;*/
  59. // Generate Guid - unique id
  60. function NewGuid() {
  61. $s = strtoupper(md5(uniqid(rand(),true)));
  62. date_default_timezone_set('Asia/Kolkata');
  63. $timestamp = date('dmYHis', time());
  64. $guidText =
  65. substr($timestamp,0,18) . '-' .
  66. substr($s,18,4) . '-' .
  67. substr($s,22,4). '-' .
  68. substr($s,26,4). '-' .
  69. substr($s,30);
  70. return $guidText;
  71. }
  72. // End Generate Guid
  73. $quotuniqueid = NewGuid();
  74. $_SESSION['quotuniqueid']=$quotuniqueid;
  75. $pathquot=null;
  76. $pathattachment=null;
  77. $allowed = array('png', 'jpg','jpeg', 'pdf', 'doc', 'docx', 'xls','xlsx','csv');
  78. /*check columns available start*/
  79. $result=mysqli_query($dbc,"show columns from quotation");
  80. $k=0;
  81. $c=0;
  82. while($row = mysqli_fetch_array($result)){
  83. $str=$row['Field'];
  84. $newstr = filter_var($str, FILTER_SANITIZE_STRING);
  85. if($newstr="Product")
  86. {
  87. $int_id = filter_var($str, FILTER_SANITIZE_NUMBER_INT);
  88. if($int_id > $k)
  89. {
  90. global $c;
  91. $c=$int_id;
  92. $k=$int_id;
  93. }
  94. }
  95. }
  96. /*check columns available end*/
  97. for ($i = 0; $i < 500; $i++)
  98. {
  99. /*if (isset($_POST['partdesc'][$i], $_POST['qty'][$i],$_POST['unitprice'][$i])) { // Make sure both are filled in*/
  100. // Do stuff with this row of the form
  101. $product=$_POST['product'][$i];
  102. $partd=$_POST['partdesc'][$i];
  103. $qt=$_POST['qty'][$i];
  104. $unitp=$_POST['unitprice'][$i];
  105. $licencefor=$_POST['licencefor'][$i];
  106. $hsnsac=$_POST['hsnsac'][$i];
  107. if(!empty($product))
  108. {
  109. if($i=='0')
  110. {
  111. //Get the temp file path
  112. $tmpFilePath = $_FILES['uplfiles']['tmp_name'][$i];
  113. //Make sure we have a file path
  114. if ($tmpFilePath != ""){
  115. //Setup our new file path
  116. $newFilePath = "../../../../uploadfiles/quotation/".$quotuniqueid."-".$_FILES['uplfiles']['name'][$i];
  117. //Upload the file into the temp dir
  118. if(move_uploaded_file($tmpFilePath, $newFilePath)) {
  119. //Handle other code here
  120. $newFilePathq = $quotuniqueid."-".$_FILES['uplfiles']['name'][$i];
  121. }
  122. }
  123. //Get the temp attachment path
  124. $tmpFilePath = $_FILES['attachment']['tmp_name'][$i];
  125. //Make sure we have a file path
  126. if ($tmpFilePath != ""){
  127. //Setup our new file path
  128. $newFilePath1 = "../../../../uploadfiles/quotation/".$quotuniqueid."-".$_FILES['attachment']['name'][$i];
  129. //Upload the file into the temp dir
  130. if(move_uploaded_file($tmpFilePath, $newFilePath1)) {
  131. //Handle other code here
  132. $newFilePatha = $quotuniqueid."-".$_FILES['attachment']['name'][$i];
  133. }
  134. }
  135. $ad=mysqli_query($dbc,"insert into `quotation` (`Representive`,`RMail`,`UniqueId`,`Company`,`Product1`,`Tax`,`Currency`,`HSNSAC1`,`ServiceName`,`ServiceCost`,`ServiceTax`,`FreightName`,`FreightCost`,`FreightTax`,`PartDescription1`,`Quantity1`,`UnitPrice1`,`Validity`,`Delivery`,`Payment`,`QuotationPath1`,`Attachment1`,`Remarks`,`AddressReq`,`LicenceFor1`,`ExpectedClosure`,`QuotFormName`) values ('$rep','$rmail','$quotuniqueid','$company','$product','$tax','$currency','$hsnsac','$servicename','$servicecost','$servicetax','$freightname','$freightcost','$freighttax','$partd','$qt','$unitp','$validity','$delivery','$payment','$newFilePathq','$newFilePatha','$remarks','$addreq','$licencefor','$expectedclosure','$quotformname')");
  136. /*$ad=mysqli_query($dbc,"insert into `quotation_all` (`Representive`,`RMail`,`UniqueId`,`Company`,`Product1`,`Tax`,`Currency`,`HSNSAC1`,`ServiceName`,`ServiceCost`,`ServiceTax`,`FreightName`,`FreightCost`,`FreightTax`,`PartDescription1`,`Quantity1`,`UnitPrice1`,`Validity`,`Delivery`,`Payment`,`QuotationPath1`,`Attachment1`,`Remarks`,`AddressReq`,`LicenceFor1`,`ExpectedClosure`,`QuotFormName`) values ('$rep','$rmail','$quotuniqueid','$company','$product','$tax','$currency','$hsnsac','$servicename','$servicecost','$servicetax','$freightname','$freightcost','$freighttax','$partd','$qt','$unitp','$validity','$delivery','$payment','$newFilePathq','$newFilePatha','$remarks','$addreq','$licencefor','$expectedclosure','$quotformname')");*/
  137. }
  138. elseif($i>=1)
  139. {
  140. if($i==$c)
  141. {
  142. $productnew="Product".($c+1);
  143. $partdescnew="PartDescription".($c+1);
  144. $quantitynew="Quantity".($c+1);
  145. $unitpricenew="UnitPrice".($c+1);
  146. $hsnsacnew="HSNSAC".($c+1);
  147. $quotationpathnew="QuotationPath".($c+1);
  148. $attachmentnew="Attachment".($c+1);
  149. $licencefornew="LicenceFor".($c+1);
  150. mysqli_query($dbc,"ALTER TABLE `quotation` ADD `$productnew` TEXT NULL, ADD `$partdescnew` TEXT NULL,ADD `$quantitynew` TEXT NULL,ADD `$unitpricenew` TEXT NULL,ADD `$hsnsacnew` TEXT NULL,ADD `$quotationpathnew` TEXT NULL,ADD `$attachmentnew` TEXT NULL,ADD `$licencefornew` TEXT NULL");
  151. mysqli_query($dbc,"ALTER TABLE `quotation_all` ADD `$productnew` TEXT NULL, ADD `$partdescnew` TEXT NULL,ADD `$quantitynew` TEXT NULL,ADD `$unitpricenew` TEXT NULL,ADD `$hsnsacnew` TEXT NULL,ADD `$quotationpathnew` TEXT NULL,ADD `$attachmentnew` TEXT NULL,ADD `$licencefornew` TEXT NULL");
  152. $c=$c+1;
  153. }
  154. //Get the temp file path
  155. $tmpFilePath = $_FILES['uplfiles']['tmp_name'][$i];
  156. //Make sure we have a file path
  157. if ($tmpFilePath != ""){
  158. //Setup our new file path
  159. $newFilePath = "../../../../uploadfiles/quotation/".$quotuniqueid."-".$_FILES['uplfiles']['name'][$i];
  160. //Upload the file into the temp dir
  161. if(move_uploaded_file($tmpFilePath, $newFilePath)) {
  162. //Handle other code here
  163. $newFilePathtwo = $quotuniqueid."-".$_FILES['uplfiles']['name'][$i];
  164. }
  165. }
  166. $ii=$i+1;
  167. $productcolumn="Product".$ii;
  168. $partdescolumn="PartDescription".$ii;
  169. $quantitycolumn="Quantity".$ii;
  170. $unitpricecolumn="UnitPrice".$ii;
  171. $quotationpathcolumn="QuotationPath".$ii;
  172. $hsnsaccolumn="HSNSAC".$ii;
  173. $licenceforcolumn="LicenceFor".$ii;
  174. $ad=mysqli_query($dbc,"update `quotation` set `$productcolumn`='$product',`$partdescolumn`='$partd',`$quantitycolumn`='$qt',`$unitpricecolumn`='$unitp',`$quotationpathcolumn`='$newFilePathtwo',`$hsnsaccolumn`='$hsnsac',`$licenceforcolumn`='$licencefor' where `RMail`='$rmail' and `UniqueId`='$quotuniqueid' ");
  175. /*$ad=mysqli_query($dbc,"update `quotation_all` set `$productcolumn`='$product',`$partdescolumn`='$partd',`$quantitycolumn`='$qt',`$unitpricecolumn`='$unitp',`$quotationpathcolumn`='$newFilePathtwo',`$hsnsaccolumn`='$hsnsac',`$licenceforcolumn`='$licencefor' where `RMail`='$rmail' and `UniqueId`='$quotuniqueid' ");*/
  176. }
  177. else
  178. {
  179. echo '<script>alert("Sorry!! Maximum Description Reached");location.replace("../../../opr/quotgen.php");</script>';
  180. }
  181. }
  182. else
  183. {
  184. break;
  185. }
  186. }
  187. if($ad>0)
  188. {
  189. //echo '<script>alert("Data Inserted Successfully");location.replace("../../../opr/quotgen.php");</script>';
  190. echo '<script>location.replace("../../../opr/quotverify.php");</script>';
  191. /*echo '<script>location.replace("quotation.php");</script>';*/
  192. }
  193. else
  194. {
  195. echo '<script>alert("Data not Inserted ");location.replace("../../../opr/quotgen.php");</script>';
  196. }
  197. }
  198. echo '<script>location.replace("../../../opr/quotgen.php");</script>';
  199. ?>