PageRenderTime 67ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

/manager/auth/order/quotation/updquot.php

https://bitbucket.org/nav_subhamkumar/crm
PHP | 354 lines | 169 code | 112 blank | 73 comment | 20 complexity | f8a39244b98bbd2a1c21e829c45e516a 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. $quotno=$_POST['quotno'];
  26. $company=$_POST['company'];
  27. /*$array = explode('.', $companywfid);
  28. $fid=$array[0];
  29. $company=$array[1];*/
  30. /*$quotationnumber=$_POST['quotationnumber'];
  31. $_SESSION['quotationnumber']=$quotationnumber;*/
  32. $qtype=$_POST['qtype'];
  33. //$_SESSION['qtype']=$qtype;
  34. $quotuniqueid=$_POST['uniqueid'];
  35. $_SESSION['qu']=$quotuniqueid;
  36. /*$quotuniqueid=$_POST['uniqueid'];
  37. $_SESSION['quotuniqueid']=$quotuniqueid;*/
  38. $currency=$_POST['currency'];
  39. $hsnsac=$_POST['hsnsac'];
  40. $validity=$_POST['validity'];
  41. $delivery=$_POST['delivery'];
  42. $service=$_POST['service'];
  43. $payment=$_POST['payment'];
  44. $servicename=$_POST['servicename'];
  45. $servicecost=$_POST['servicecost'];
  46. $servicetax=$_POST['servicetax'];
  47. $freightname=$_POST['freightname'];
  48. $freightcost=$_POST['freightcost'];
  49. $freighttax=$_POST['freighttax'];
  50. $expectedclosure=$_POST['expectedclosure'];
  51. $addreq=$_POST['addreq'];
  52. $quotformname=$_POST['quotformname'];
  53. $remarks=$_POST['remarks'];
  54. $tax=implode(',', $_POST['tax']);
  55. $_SESSION['fid']=null;
  56. $_SESSION['qcompany']=$company;
  57. /*$_SESSION['qproduct']=$product;*/
  58. // Generate Guid - unique id
  59. function NewGuid() {
  60. $s = strtoupper(md5(uniqid(rand(),true)));
  61. date_default_timezone_set('Asia/Kolkata');
  62. $timestamp = date('dmYHis', time());
  63. $guidText =
  64. substr($timestamp,0,18) . '-' .
  65. substr($s,18,4) . '-' .
  66. substr($s,22,4). '-' .
  67. substr($s,26,4). '-' .
  68. substr($s,30);
  69. return $guidText;
  70. }
  71. // End Generate Guid
  72. if($qtype>1)
  73. {
  74. $quotuniqueid = NewGuid();
  75. }
  76. $_SESSION['quotuniqueid']=$quotuniqueid;
  77. $pathquot=null;
  78. $pathattachment=null;
  79. $allowed = array('png', 'jpg','jpeg', 'pdf', 'doc', 'docx', 'xls','xlsx','csv');
  80. /*upload quotation*/
  81. /*if(isset($_FILES['uplfiles']) && $_FILES['uplfiles']['error'] == 0){
  82. $extension = pathinfo($_FILES['uplfiles']['name'], PATHINFO_EXTENSION);
  83. if(!in_array(strtolower($extension), $allowed)){
  84. }
  85. if(move_uploaded_file($_FILES['uplfiles']['tmp_name'], '../../../../../uploadfiles/quotation/'.$company.'.'.$fid.'.'.$_FILES['uplfiles']['name'])){
  86. global $path;
  87. $pathquot=$company.'.'.$fid.'.'.$_FILES['uplfiles']['name'];
  88. }
  89. }
  90. */
  91. // Count # of uploaded files in array
  92. /*$total = count($_FILES['uplfiles']['name']);*/
  93. // Loop through each file
  94. /*for( $i=0 ; $i < $total ; $i++ ) {*/
  95. //Get the temp file path
  96. /*$tmpFilePath = $_FILES['uplfiles']['tmp_name'][$i];*/
  97. //Make sure we have a file path
  98. /*if ($tmpFilePath != ""){*/
  99. //Setup our new file path
  100. /*$newFilePath = "../../../../../uploadfiles/quotation/" . $_FILES['uplfiles']['name'][$i];*/
  101. //Upload the file into the temp dir
  102. /*if(move_uploaded_file($tmpFilePath, $newFilePath)) {*/
  103. //Handle other code here
  104. /* }
  105. }
  106. }*/
  107. /*check columns available start*/
  108. $result=mysqli_query($dbc,"show columns from quotation");
  109. $k=0;
  110. $c=0;
  111. while($row = mysqli_fetch_array($result)){
  112. $str=$row['Field'];
  113. $newstr = filter_var($str, FILTER_SANITIZE_STRING);
  114. if($newstr="Product")
  115. {
  116. $int_id = filter_var($str, FILTER_SANITIZE_NUMBER_INT);
  117. if($int_id > $k)
  118. {
  119. global $c;
  120. $c=$int_id;
  121. $k=$int_id;
  122. }
  123. }
  124. }
  125. /*check columns available end*/
  126. //echo $_POST['qty'];
  127. for ($i = 0; $i < 500; $i++)
  128. {
  129. /*if (isset($_POST['partdesc'][$i], $_POST['qty'][$i],$_POST['unitprice'][$i])) { // Make sure both are filled in*/
  130. // Do stuff with this row of the form
  131. $product=$_POST['product'][$i];
  132. $partd=$_POST['partdesc'][$i];
  133. $qt=$_POST['qty'][$i];
  134. $unitp=$_POST['unitprice'][$i];
  135. $licencefor=$_POST['licencefor'][$i];
  136. $hsnsac=$_POST['hsnsac'][$i];
  137. if(!empty($product) and !empty($unitp))
  138. {
  139. if($i=='0')
  140. {
  141. //Get the temp file path
  142. $tmpFilePath = $_FILES['uplfiles']['tmp_name'][$i];
  143. //Make sure we have a file path
  144. if ($tmpFilePath != ""){
  145. //Setup our new file path
  146. $newFilePath = "../../../../uploadfiles/quotation/".$quotuniqueid."-".$_FILES['uplfiles']['name'][$i];
  147. //Upload the file into the temp dir
  148. if(move_uploaded_file($tmpFilePath, $newFilePath)) {
  149. //Handle other code here
  150. $newFilePathq = $quotuniqueid."-".$_FILES['uplfiles']['name'][$i];
  151. }
  152. }
  153. //Get the temp attachment path
  154. $tmpFilePath = $_FILES['attachment']['tmp_name'][$i];
  155. //Make sure we have a file path
  156. if ($tmpFilePath != ""){
  157. //Setup our new file path
  158. $newFilePath1 = "../../../../uploadfiles/quotation/".$quotuniqueid."-".$_FILES['attachment']['name'][$i];
  159. //Upload the file into the temp dir
  160. if(move_uploaded_file($tmpFilePath, $newFilePath1)) {
  161. //Handle other code here
  162. $newFilePatha = $quotuniqueid."-".$_FILES['attachment']['name'][$i];
  163. }
  164. }
  165. $ad=mysqli_query($dbc,"insert into `quotation_all` (`Representive`,`RMail`,`UniqueId`,`QuotNo`,`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','$quotno','$company','$product','$tax','$currency','$hsnsac','$servicename','$servicecost','$servicetax','$freightname','$freightcost','$freighttax','$partd','$qt','$unitp','$validity','$delivery','$payment','$newFilePathq','$newFilePatha','$remarks','$addreq','$licencefor','$expectedclosure','$quotformname')");
  166. $ad=mysqli_query($dbc,"update `quotation` set `UniqueId`='$quotuniqueid',`Company`='$company',`Product1`='$product',`Tax`='$tax',`Currency`='$currency',`HSNSAC1`='$hsnsac',`ServiceName`='$servicename',`ServiceCost`='$servicecost',`ServiceTax`='$servicetax',`FreightName`='$freightname',`FreightCost`='$freightcost',`FreightTax`='$freighttax',`PartDescription1`='$partd',`Quantity1`='$qt',`UnitPrice1`='$unitp',`Validity`='$validity',`Delivery`='$delivery',`Payment`='$payment',`QuotationPath1`='$newFilePathq',`Attachment1`='$newFilePatha',`Remarks`='$remarks',`AddressReq`='$addreq',`LicenceFor1`='$licencefor',`ExpectedClosure`='$expectedclosure',`QuotFormName`='$quotformname' where `QuotNo`='$quotno' ");
  167. }
  168. elseif($i>=1)
  169. {
  170. if($i==$c)
  171. {
  172. $productnew="Product".($c+1);
  173. $partdescnew="PartDescription".($c+1);
  174. $quantitynew="Quantity".($c+1);
  175. $unitpricenew="UnitPrice".($c+1);
  176. $hsnsacnew="HSNSAC".($c+1);
  177. $quotationpathnew="QuotationPath".($c+1);
  178. $attachmentnew="Attachment".($c+1);
  179. $licencefornew="LicenceFor".($c+1);
  180. 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");
  181. 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");
  182. $c=$c+1;
  183. }
  184. //Get the temp file path
  185. $tmpFilePath = $_FILES['uplfiles']['tmp_name'][$i];
  186. //Make sure we have a file path
  187. if ($tmpFilePath != ""){
  188. //Setup our new file path
  189. $newFilePath = "../../../../uploadfiles/quotation/".$quotuniqueid."-".$_FILES['uplfiles']['name'][$i];
  190. //Upload the file into the temp dir
  191. if(move_uploaded_file($tmpFilePath, $newFilePath)) {
  192. //Handle other code here
  193. $newFilePathtwo = $quotuniqueid."-".$_FILES['uplfiles']['name'][$i];
  194. }
  195. }
  196. $ii=$i+1;
  197. $productcolumn="Product".$ii;
  198. $partdescolumn="PartDescription".$ii;
  199. $quantitycolumn="Quantity".$ii;
  200. $unitpricecolumn="UnitPrice".$ii;
  201. $quotationpathcolumn="QuotationPath".$ii;
  202. $hsnsaccolumn="HSNSAC".$ii;
  203. $licenceforcolumn="LicenceFor".$ii;
  204. $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' ");
  205. $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' ");
  206. }
  207. else
  208. {
  209. echo '<script>alert("Sorry!! Maximum Description Reached");location.replace("../../../opr/quotgen.php");</script>';
  210. }
  211. }
  212. else
  213. {
  214. break;
  215. }
  216. }
  217. if($ad>0)
  218. {
  219. echo '<script>location.replace("../../../opr/quotverify.php");</script>';
  220. }
  221. else
  222. {
  223. echo '<script>alert("Data not Updated ");location.replace("../../../opr/quotdash.php");</script>';
  224. }
  225. }
  226. echo '<script>location.replace("../../../opr/quotdash.php");</script>';
  227. ?>