During file uploading Quote Number is generating

Hi, There

first my code

i create in modules/AOS_Quotes/Vardefs.php.

<?php 'file_mime_type' => array( 'name' => 'file_mime_type', 'vname' => 'LBL_FILE_MIME_TYPE', 'type' => 'varchar', 'len' => '100', 'comment' => 'Attachment MIME type', 'importable' => false, ), 'file_url'=> array( 'name'=>'file_url', 'vname' => 'LBL_FILE_URL', 'type'=>'function', 'function_class'=>'UploadFile', 'function_name'=>'get_upload_url', 'function_params'=> array('$this'), 'source'=>'function', 'reportable'=>false, 'comment' => 'Path to file (can be URL)', 'importable' => false, ), 'filename' => array( 'name' => 'filename', 'vname' => 'LBL_FILENAME', 'type' => 'file', 'dbType' => 'varchar', 'len' => '255', 'reportable'=>true, 'comment' => 'File name associated with the note (attachment)', 'importable' => false, ), with this my upload and download is fine working. But main problem is i am facing while saving the quote. The quote_number is not generating. its because during file upload, one id is creating. it should not. so it is unable to create the quote number which possible only if "bean->id" is empty. global $sugar_config; if (empty($this->id)){ unset($_POST['group_id']); unset($_POST['product_id']); unset($_POST['service_id']); if($sugar_config['dbconfig']['db_type'] == 'mssql'){ $this->number = $this->db->getOne("SELECT MAX(CAST(number as INT))+1 FROM aos_quotes"); } else { $this->number = $this->db->getOne("SELECT MAX(CAST(number as UNSIGNED))+1 FROM aos_quotes"); } if($this->number < $sugar_config['aos']['quotes']['initialNumber']){ $this->number = $sugar_config['aos']['quotes']['initialNumber']; } } Plz help me out guys. Its an error. :unsure:

I’m not sure what you are trying to do here, are you importing quotes from a csv or something?

hi andy,
i am not trying import something. i just add one filed. i.e, file upload.(attachment) (so only i gave the coding for upload file). but what happen, if i added this fileds in vardefs, file is uploading fine but the after save quote number is not generating. (which is a problem). and

global $sugar_config;

if (empty($this->id)){

if($sugar_config == ‘mssql’){
$this->number = $this->db->getOne(“SELECT MAX(CAST(number as INT))+1 FROM aos_quotes”);
} else {
$this->number = $this->db->getOne(“SELECT MAX(CAST(number as UNSIGNED))+1 FROM aos_quotes”);

if($this->number < $sugar_config){
$this->number = $sugar_config;

this portion of code for generating the quote number. but whatis happening i includeed the file upload thing in vardef file so it is creating one random id. so this above condition is failing to satisfy and quote number is not generating.

i hope i am able to describe u my problem.

That’s an interesting problem you have there. Why do you need the upload file field in the invoice record itself? Could you not just use SuiteCRM’s built in documents module to handle the upload files and link them to the invoice via a relationship?

i can understand u. but the requirement is like that in quotes module there is a possibilty to attach one hard copy of the invoice. so only i rquired this.

plz help me out with this.

The way you are trying to do it is not going to work. When you upload a file an id is created because thats how file will be linked to the record. If you unset the the id so that the quote can automatically generate a quote number then the uploaded file link will be lost as its linked to the quote via the id that is generated.

You will either have to re-write the code to significantly to handle this or as I suggest go into studio and create a relationship between Quotes and Documents. One to One will create a filed in Quotes many to many will create a documents subpanel. You then upload the file into the document record.

1 Like

Actually there may be an alternative method of doing this with a custom field type. let me look into this.

yah. i am also thinking the same . beacuse if i mak a relationship now that wil not fulfill my requirement.
i am looking forward to ur answer. :slight_smile:

My method will still cause the same problem.

Have you tried a before save logic hook? You use that to do an sql query which will get the id of the last previously saved record. Then you just add 1 onto it and set the id.

ok that might be one solution. but i dont knw whether it is a correct way of doing that or not.

its probably not the best way but It would be the simplest way considering your only other alternative is to hack the code of aos_quotes. That random id is always generated when upload a file in sugar so how do you get round that…

ok. andy thanks for your time. :slight_smile: