vtiger Forum Index vtiger
The Honest Open Source CRM
 

Unique serial number of Product
Click here to go to the original topic
Goto page 1, 2  Next
 
       vtiger Forum Index -> Usability & Themes - 5.0.4
Previous topic :: Next topic  
Author Message
jagi



Joined: 17 Jan 2006
Posts: 115
Location: Poland

Posted: Sun May 18, 2008 3:01 pm    Post subject: Unique serial number of Product  

Unique serials number - not elegance but working solution
( based on accounts check for ) + info about nr of duplication (existing before applying patch )
- not work in AJAX edit

1. added in file:///D:/SVN/vTiger/artCode/5.0.4_unique/modules/Products/Save.php
Code:
if(isset($_REQUEST['dup_check']) && $_REQUEST['dup_check'] != '')
{
   //started
   $value = $_REQUEST['serial_no'];
   $query = "SELECT serialno FROM vtiger_products, vtiger_crmentity WHERE serialno =? and vtiger_products.productid = vtiger_crmentity.crmid and vtiger_crmentity.deleted != 1";
//$query = "SELECT serialno FROM vtiger_products WHERE serialno =?";  // wszystkie nawet skasowane
   $result = $adb->pquery($query, array($value));
   $result_nrs = $adb->num_rows($result);
   if($result_nrs > 0)
    //.$result[0]
   {
echo $mod_strings['LBL_SERIALNO_EXIST'].$result_nrs;
   }
   
   else
   {
   echo 'SUCCESS';
   }
   die;
}
//Ended

2. change in
file:///D:/SVN/vTiger/artCode/5.0.4_unique/Smarty/templates/Inventory/InventoryCreateView.tpl
Code:
<input title="{$APP.LBL_SAVE_BUTTON_TITLE}" accessKey="{$APP.LBL_SAVE_BUTTON_KEY}" class="crmbutton small save" onclick="this.form.action.value='Save';  return validateInventory('{$MODULE}')" type="submit" name="button" value="  {$APP.LBL_SAVE_BUTTON_LABEL}  " style="width:70px" >
to
Code:
<input title="{$APP.LBL_SAVE_BUTTON_TITLE}" accessKey="{$APP.LBL_SAVE_BUTTON_KEY}" class="crmbutton small save" onclick="this.form.action.value='Save';  if(validateInventory('{$MODULE}'))AjaxDuplicateValidate('Products','serial_no',this.form);" type="button" name="button" value=" {$APP.LBL_SAVE_BUTTON_LABEL}  " style="width:70px" >
copy step in
file:///D:/SVN/vTiger/artCode/5.0.4_unique/Smarty/templates/Inventory/InventoryEditView.tpl

3. add in
\include\js\Inventory.js

Code:
function AjaxDuplicateValidate(module,fieldname,oform)
{
      var fieldvalue = encodeURIComponent(getObj(fieldname).value);
   
      var url = "module="+module+"&action="+module+"Ajax&file=Save&"+fieldname+"="+fieldvalue+"&dup_check=true"
      new Ajax.Request(
                            'index.php',
                              {queue: {position: 'end', scope: 'command'},
                                      method: 'post',
                                      postBody:url,
                                      onComplete: function(response) {
                                              var str = response.responseText
                                              if(str.indexOf('SUCCESS') > -1)
                                              {
                                                      oform.submit();
                                              }else
                                              {
                                                      alert(str);
                                              }
                                      }
                              }
                              );
}


4. add in langs files like in english
\modules\Products\language\en_us.lang.php

Code:
'LBL_SERIALNO_EXIST' => 'Serial Number exist ! Owned: ',

test this on
http://vtiger.artcode.eu

BTW. I suggest to make new in vtiger_field
typeofdata : (U)nique
to simply apply unique on all fields
Back to top  
joebordes



Joined: 18 Aug 2006
Posts: 1089
Location: Alicante/Valencia, Spain

Posted: Sun May 18, 2008 4:05 pm    Post subject: Re: Unique serial number of Product  

Useful code.
I like the idea of a new Unique uitype, hope it catches on.

Thanks Jagi.
Joe
TSolucio
Back to top  
jagi



Joined: 17 Jan 2006
Posts: 115
Location: Poland

Posted: Mon May 19, 2008 8:12 am    Post subject: Re: Unique serial number of Product  

Not do this
Quote:
copy step in
file:///D:/SVN/vTiger/artCode/5.0.4_unique/Smarty/templates/Inventory/InventoryEditView.tpl
Code:
in edition need corrected code ...

BTW.
checking account name not works in edition of existing account ( can be duplicated ) , too
Back to top  
jagi



Joined: 17 Jan 2006
Posts: 115
Location: Poland

Posted: Mon May 19, 2008 11:24 am    Post subject: Re: Unique serial number of Product  

corrected for edition

1. vtigercrm\include\js\Inventory.js
Code:
function AjaxDuplicateValidate(module,fieldname,oform)
{
      var fieldvalue = encodeURIComponent(getObj(fieldname).value);
     var record = encodeURIComponent(getObj("record").value);
   
      var url = "module="+module+"&action="+module+"Ajax&file=Save&"+fieldname+"="+fieldvalue+"&dup_check=true&record="+record+""
      new Ajax.Request(
                            'index.php',
                              {queue: {position: 'end', scope: 'command'},
                                      method: 'post',
                                      postBody:url,
                                      onComplete: function(response) {
                                              var str = response.responseText
                                              if(str.indexOf('SUCCESS') > -1)
                                              {
                                                      oform.submit();
                                              }else
                                              {
                                                      alert(str);
                                              }
                                      }
                              }
                              );
}

2. vtigercrm\modules\Products\Save.php
Code:
if(isset($_REQUEST['dup_check']) && $_REQUEST['dup_check'] != '')
{
   //started
   $value = $_REQUEST['serial_no'];
   $query = "SELECT serialno,productid FROM vtiger_products, vtiger_crmentity WHERE serialno =? and vtiger_products.productid = vtiger_crmentity.crmid and vtiger_crmentity.deleted != 1";
   $result = $adb->pquery($query, array($value));
   $result_nrs = $adb->num_rows($result);
   
   $productid = $adb->query_result($result,0,"productid");
   $record_id= $_REQUEST['record'];
// tworzenie nowego
   if($result_nrs > 0 AND $record_id == NULL)
   {
echo $mod_strings['LBL_SERIALNO_EXIST'].$result_nrs." Duplicat id=".$productid;
   }
// przy edycji umozliwia zapis  produktu , ktory ma juz zapisany nr seryjny  - bo zawsze 1 znajduje
   elseif($result_nrs > 1 AND $record_id == $productid)
   {
echo $mod_strings['LBL_SERIALNO_EXIST'].$result_nrs." Duplicat id=".$productid ;
   }
// przy edycji gdy zamieniamy serial no na juz istniejacy   
   elseif($result_nrs > 0 AND $record_id !== $productid)
   {
echo $mod_strings['LBL_SERIALNO_EXIST'].$result_nrs." Duplicat id=".$productid;
   }
//      
   else
   {
   echo 'SUCCESS';
   }
   die;
}
//Ended
Back to top  
AndrewG



Joined: 16 Aug 2008
Posts: 30
Location: Poland

Posted: Sat Aug 16, 2008 8:38 am    Post subject: Re: Unique serial number of Product  

Jagi, thanks for this useful code.
I have put it to my vtiger files and it works, but partially.
When I create new product it works properly but in edit mode
I can still save product with duplicate serial numer.

Looks like I'm doing something wrong.
You did not describe where exactly changes should be pasted to.
I think I pasted them in to wrong place.
May u help?
thanks in advance
Andrew
Back to top  
jagi



Joined: 17 Jan 2006
Posts: 115
Location: Poland

Posted: Sat Aug 16, 2008 10:49 am    Post subject: Re: Unique serial number of Product  

I made new correct code edition - check Your problem working on vtiger.artcode.eu - if OK - write to me
Back to top  
edlentz



Joined: 18 Nov 2005
Posts: 509
Location: Midland, Mi.

Posted: Sat Aug 16, 2008 11:54 am    Post subject: Re: Unique serial number of Product  

Very useful! Just one question, When I go to sell that product with the serial number, how can I make sure I am getting the right product. If I have 5 widgets with different serial numbers how do I know which widget I am selling?
Back to top  
AndrewG



Joined: 16 Aug 2008
Posts: 30
Location: Poland

Posted: Sat Aug 16, 2008 12:22 pm    Post subject: Re: Unique serial number of Product  

Jagi
I already checked it at your site and it works properly.
Back to top  
jagi



Joined: 17 Jan 2006
Posts: 115
Location: Poland

Posted: Sat Aug 16, 2008 12:35 pm    Post subject: Re: Unique serial number of Product  

AndrewG wrote: Jagi
I already checked it at your site and it works properly.

vtiger\modules\Products\Save.php
after line: $search=$_REQUEST['search_url'];

Code:
$focus = new Products();
//added to fix 4600
$search=$_REQUEST['search_url'];
// artcode serialno duplicated check
if(isset($_REQUEST['dup_check']) && $_REQUEST['dup_check'] != '')
{
   //started
   $value = $_REQUEST['serial_no'];
   $query = "SELECT serialno,productid FROM vtiger_products, vtiger_crmentity WHERE serialno =? and vtiger_products.productid = vtiger_crmentity.crmid and vtiger_crmentity.deleted != 1";
   $result = $adb->pquery($query, array($value));
   $result_nrs = $adb->num_rows($result);
   
   $productid = $adb->query_result($result,0,"productid");
   $serialno = $adb->query_result($result,0,"serialno");
   $record_id= $_REQUEST['record'];
   
// tworzenie nowego
   if($result_nrs > 0 AND $record_id == NULL AND $serialno!== '')
   {
echo $mod_strings['LBL_SERIALNO_EXIST'].$result_nrs." Duplicat id=".$productid." NOWY";
   }
// przy edycji umozliwia zapis  produktu , ktory ma juz zapisany nr seryjny  - bo zawsze 1 znajduje
   elseif($result_nrs > 1 AND $record_id == $productid)
   {
echo $mod_strings['LBL_SERIALNO_EXIST'].$result_nrs." Duplicat id=".$productid." EDYCJA ZAPIS" ;
   }
// przy edycji gdy zamieniamy serial no na juz istniejacy   
   elseif($result_nrs > 0 AND $record_id !== $productid AND $serialno!== '')
   {
echo $mod_strings['LBL_SERIALNO_EXIST'].$result_nrs." Duplicat id=".$productid." EDYCJA ZMIANA";
   }
//      
   else
   {
   echo 'SUCCESS';
   }
   die;
}
//Ended



if(isset($_REQUEST['record']))
Back to top  
jagi



Joined: 17 Jan 2006
Posts: 115
Location: Poland

Posted: Sat Aug 16, 2008 1:02 pm    Post subject: Re: Unique serial number of Product  

edlentz wrote: Very useful! Just one question, When I go to sell that product with the serial number, how can I make sure I am getting the right product. If I have 5 widgets with different serial numbers how do I know which widget I am selling?
I'm not using vTiger for selling function, but in my opinion You can search by serialno ? ( long time ago I made serialno functionality adds - I make customized searching for serialno and custom inventory lists with serialno - but for my own use only /many changes/ - You can look on vtiger.artcode.eu - Inventory - serialno list view)
Back to top  
 
       vtiger Forum Index -> Usability & Themes - 5.0.4 Goto page 1, 2  Next
Page 1 of 2


Powered by phpBB Search Engine Indexer
Powered by phpBB 2.0.15 © 2001, 2002 phpBB Group